Exetools  

Go Back   Exetools > General > Developer Section

Notices

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 05-17-2015, 19:13
Git's Avatar
Git Git is offline
Old Git
 
Join Date: Mar 2002
Location: Torino
Posts: 1,096
Rept. Given: 220
Rept. Rcvd 265 Times in 157 Posts
Thanks Given: 91
Thanks Rcvd at 208 Times in 122 Posts
Git Reputation: 200-299 Git Reputation: 200-299 Git Reputation: 200-299
Code timing snippet

Is it ok to post small pieces of code here that could be useful for people to include in programs?. If not, please delete or move the message.

Here is a trivial snippet of C source that will measure the time between two calls to _ftime_s() and return the number of seconds in a double, accurate to 1millisecond. It's useful for measuring run times of functions, bruteforce loops, etc, on the fly. I've used it lot, please help yourself if useful to you or ignore otherwise.

Git

Code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/timeb.h>
#include <time.h>

int main(int argc, char * argv[])
{
	struct _timeb startTime, endTime;
	double	diftim;
	
	_ftime_s(&startTime);
	...
	...
	do things
	...
	...
	_ftime_s(&endTime);
	diftim = timediff(&startTime, &endTime);
	printf("\nProcessing time %8.3f seconds\n", diftim);
}


double timediff(struct _timeb *timstart, struct _timeb *timend)
{
	__int64	sTime, eTime;

	eTime = timend->millitm + 1000 * timend->time;
	sTime = timstart->millitm + 1000 * timstart->time;

	return (eTime - sTime) / 1000.0;
}

// The  _ftime_s(&endTime) statement could go in the timediff() function
// if the calling time of timediff() is insignificant.
Reply With Quote
The Following 11 Users Say Thank You to Git For This Useful Post:
ahmadmansoor (05-18-2015), b30wulf (08-01-2015), canopus (08-02-2015), Debugger (05-19-2015), Indigo (07-19-2019), Loki (01-02-2018), mr.exodia (05-17-2015), niculaita (05-24-2015), rasta (12-31-2017), te$ter (05-18-2015), zeytunak (05-19-2015)
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code snippet for Base34 Encoding TempoMat General Discussion 11 03-29-2020 17:58
Any ideas about executing phpinfo() in this code snippet XnHandt General Discussion 0 12-28-2012 00:46
How to execute a snippet of code before the main execution! Android General Discussion 8 10-04-2006 01:22


All times are GMT +8. The time now is 16:41.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX
( 1998 - 2020 )