473,385 Members | 1,357 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Measure time

Hello i am new to this forum...can you help me solve this problem..
I have a function encrypt() which encrypts data from a file in 16 bytes till end of file which in turn calls other 4 functions...and i need to measure the time it encrypts the data consecutively for all the 4 functions till end of file...
I am fwding you the codes...Please help me out...

Expand|Select|Wrap|Line Numbers
  1. int Encrypt (word8 a[4][MAXBC], word8 rk[MAXROUNDS+1][4][MAXBC])
  2. {    // Encryption of one blockl
  3.         int r;
  4.     sec_init();
  5.     start_time = sec();
  6.     AddRoundKey(a, rk[0]);
  7.     stop_time = sec();
  8.     Add1 = (stop_time - start_time);
  9.  
  10.     for ( r=1; r < ROUNDS; r++)
  11.     {
  12.         sec_init();
  13.         start_time = sec();
  14.             SubBytes (a,S);
  15.         stop_time = sec();
  16.          sub1 = (stop_time - start_time);
  17.  
  18.         sec_init();
  19.         start_time = sec();
  20.             ShiftRows(a);
  21.         stop_time = sec();
  22.         sft1 = (stop_time - start_time);
  23.  
  24.         sec_init();
  25.         start_time = sec();            
  26.             MixColumns(a);
  27.         stop_time = sec();
  28.         mix1 = (stop_time - start_time);
  29.  
  30.         sec_init();
  31.         start_time = sec();
  32.             AddRoundKey(a,rk[r]);
  33.         stop_time = sec();
  34.         Add2 = (stop_time - start_time);        
  35.     }
  36.     /* Last round is special; there is no MixColumns
  37.     */
  38.     sec_init();
  39.     start_time = sec();        
  40.         SubBytes (a,S);
  41.     stop_time = sec();
  42.     sub2 = (stop_time - start_time);
  43.  
  44.     sec_init();
  45.     start_time = sec();        
  46.         ShiftRows(a);
  47.     stop_time = sec();
  48.     sft2 = (stop_time - start_time);
  49.  
  50.     sec_init();
  51.     start_time = sec();        
  52.         AddRoundKey(a,rk[ROUNDS]);
  53.     stop_time = sec();
  54.     Add3 = (stop_time - start_time);
  55.  
  56.     return 0;
  57. }
// main function

// opens up a file plaintext.txt

Expand|Select|Wrap|Line Numbers
  1. char d;
  2.     ifstream myfile1 ("Plaintext.txt");
  3.     ofstream myfile3 ("Ciphertext.txt");
  4.  
  5.     myfile1.get(d);  //priming read
  6.  
  7.   while(!myfile1.eof())
  8. {
  9.       for ( j=0; j<BC; j++)
  10.       for ( i=0; i < 4; i++)        
  11.       {
  12.           a[i][j] = d; // plaintext
  13.           //cout<<a[i][j]; // to chk how many plaintext is copied
  14.           myfile1.get(d);  //reads first element of next block
  15.       }
  16.  
  17.       //sec_init();
  18.         //start_time = sec();
  19.  
  20.           Encrypt(a, rk);
  21.  
  22.         //stop_time = sec();
  23.         //enTime = (stop_time - start_time);
  24.         //sum2+=enTime;
  25.  
  26.       if (myfile3.is_open())
  27.       {
  28.           for(j=0; j< BC; j ++)
  29.               for ( i=0; i<4; i++)
  30.                   myfile3<<a[i][j];
  31.       }   
  32.       else        
  33.         cout << "Unable to open file";
  34.   }                    
  35.  
  36.       myfile3.close();
  37.     myfile1.close();
// measure performance...

Expand|Select|Wrap|Line Numbers
  1. Add = Add1 + Add2*(ROUNDS-1) + Add3;
  2.         sub = sub1*(ROUNDS-1) + sub2;
  3.         sft = sft1*(ROUNDS-1) + sft2;
  4.         mix = mix1*(ROUNDS-1);
  5.  
  6.         encryptTime = Add + sub + sft + mix;
The problem is that i am able to record the time for the first 16 bytes.. and i need to record the time for encrypting the data in the plaintext.txt file till eof()
please help me out..
Feb 16 '08 #1
1 2739
gpraghuram
1,275 Expert 1GB
I dont know how the sec() function works
But my idea would be use time_t structure and use this logic

Expand|Select|Wrap|Line Numbers
  1. time_t start,end;
  2. time(&start);
  3. <your function call>
  4. time(&end);
  5.  
  6. difftime(end,start);//this gives the time difference in seconds
  7.  
  8.  
Thanks
Raghuram
Feb 17 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Gary | last post by:
Hi, How does one set up a timer so I can measure the time to do an event? Something like this I guess the format would be, start timer...
7
by: Peng Yu | last post by:
Hi, For example, there is a function which is called many times from different places in a program. I want measure how long this function runs in total. Of course, I can use gettimeofday to...
2
by: Bond | last post by:
Hi! I'd like to measure the performance of my web page. I'd like to set a timer on the page to start when a user clicks on a link, or submit... anything where the browser requests a page from the...
6
by: cranium.2003 | last post by:
hello, If i wrote a C function then how to know that its costlier in terms of processing time,execution,compilation. I have written 2 functions for one problem but dont understand which one is...
6
by: Charles M. Reinke | last post by:
I'm using the function clock() to measure the run time of a program so that I can compare among several different algorithms. My code looks like: #include <stdio.h> #include <stdlib.h>...
3
by: Steve | last post by:
I used the QueryPerformanceCounter and QueryPerformanceFrequency methods in my VC++ 6.0 projects to measure correct time spans, for example for timeouts, how much time takes to execute certain...
13
by: Sharon | last post by:
I need to test a performance of some code of mine. I tried using the Environment.TickCount but its resolution is too low (from the MSDN remarks: The resolution of the TickCount property cannot be...
6
by: Christof Nordiek | last post by:
Hi, I'm using a WebRequest to post data to a Website. The data contains a possibly large file. How can I measure the progress of the upload for showibng a ProgressBar. thanks
4
by: halimunan | last post by:
Hello all, I have a question, how do i measure the download/upload speed... as if download rate, upload rate or kbps transfer rate. i want to do my own windows application using C# to measure the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.