BigDataSet Experientment

来源:互联网 发布:手机做笔记软件 编辑:程序博客网 时间:2024/05/17 02:29

Environment: Ubuntu 14.04 LTS with GUI

Programing Lanuage: C++ 11

System Workload: light (with no other user defined running program)


Task 1:

enerate 500 Million big int number (0 < int < 1 Trillion) and write them one number per line into a empty file.


Code:

---------------------------------------------------------------------------


void generate_bigDataSet()
{
  ofstream myfile;
  myfile.open ("example.txt");
  int r_min = 0;
  int r_max = int (pow(10.0, 9.0));
  for(int i=0; i<0.5*r_max;i++)
  {


      myfile << true_random(r_min,r_max) << "\n";
  }
  myfile.close();


}

---------------------------------------------------------------------------

Time Consumed: 298.322 s

File Size: 4.9 GB




Task 2:

Generate a int number which is not in the big int data set created above


Code:

----------------------------------------------------------------------------------------------

int collision_detection()
{
   int i;
   int j;
   char buffer[300];
   int guess;
   string str_buffer;
   int int_buffer;
   int round = 0;


   int r_min = 0;
   int r_max = int (pow(10.0, 9.0));


   ifstream myfile("example.txt");


    while(true)
    {
      round += 1;
      cout << "Round " << round << " Processing...\n";
      ifstream myfile("example.txt");
       if(myfile.is_open())
       {
         guess = true_random(r_min, r_max);    //pick a guess;
         for(i=0; i<0.5*r_max;i++)
         {
            myfile.getline(buffer,300);
            str_buffer = {buffer};
            int_buffer = stoi(str_buffer);
            if(guess == int_buffer)
            {
                cout << "Inloop Fail" << guess << "\n";
                break;
            }


            if(i == (0.5*r_max-1))
            {
                cout << guess;
                return guess;
            }
         }
       }
       else
         cout << "Unable to open file";
       myfile.close();
    }
   return 0;
}

--------------------------------------------------------------------------------------------------------------------------------

Time Consumed: 67.536 s








0 0
原创粉丝点击