473,587 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Measure time

1 New Member
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 2752
gpraghuram
1,275 Recognized Expert Top Contributor
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
330
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
1291
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 measure its running time. But it looks a little cumbersome. I'm wondering whether there is a class for it. Thanks!
2
1993
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 server. The idea would be to set a hidden form variable to the current time when an action occurs, then when the page from the server is returned,...
6
1814
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 best from Opereating System's overhead point of view. so i want tool that measure it. If this is not right place to ask then tell me where to ask in...
6
61814
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> #include <assert.h> #include <time.h> int main() { clock_t start, stop;
3
3856
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 method etc I wonder whether there is something similar in .NET to measure time spans? Meantime I still use these methods through DllImport ...
13
10576
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 less than 500 milliseconds.), I also tried the DateTime and it also gives me minimum resolution of 500 milliseconds. But I need to measure much less...
6
1648
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
12848
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 download speed. the idea is this. 1. i will put a file at a serverA. 2. i download the file 3. i measure the speed of the download(how long it...
0
7920
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7849
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7973
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5394
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1454
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1189
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.