Boost logo

Boost Users :

Subject: [Boost-users] how could I output the data of matrix(ublas) to txt file faster?
From: Samurai Deeper (typhoonking77_at_[hidden])
Date: 2010-09-13 04:33:56


Example

/***********begin**************/
void testMatrixRow()
{
  matrix<double> m(1920, 1080);
  clock_t begin,end;

  begin = clock();
  for(unsigned int i = 0; i < m.size1(); ++i)
    for(unsigned int j = 0; j < m.size2(); j++)
    {
      m.insert_element(i, j, i*3 + j);
    }
  end = clock();
  cout<<"time of inserting data : "<<(double)(end-begin)/CLOCKS_PER_SEC<<"
"<<endl;
  
  ofstream ob1("testing.txt",ios::out,ios::binary);

  begin = clock();
  for (unsigned i = 0; i < m.size1 (); ++ i)
  {
    for(unsigned int j = 0; j < m.size2(); j++)
      ob1<<m(i, j);
    
  }
  end = clock();
  cout<<"time of regular output : "<<(double)(end-begin)/CLOCKS_PER_SEC<<"
"<<endl;

  begin = clock();
  for (unsigned i = 0; i < m.size1 (); ++ i)
  {
    matrix_row<matrix<double> > mr(m, i);
    ob1.write((const char*)&mr(0), mr.size());
    ob1<<endl;
    
  }
  end = clock();
  cout<<"time of nonregular output :
"<<(double)(end-begin)/CLOCKS_PER_SEC<<" "<<endl;

  ob1.close();
}
/***********end**************/

As expected,ob1.write is much more faster than ob1<<
But the results are not I want(ob1<< is)
Do I have any way to solve this problem?
Thanks a lot

-- 
View this message in context: http://old.nabble.com/how-could-I-output-the-data-of-matrix%28ublas%29-to-txt-file-faster--tp29695862p29695862.html
Sent from the Boost - Users mailing list archive at Nabble.com.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net