calculate time of code ? time comparaison between CPU & GPU

hello,

in my program with cuda i would calculate time of executing of the program

when i display the result i don’t know the unit of ( time_d and time_h ) it’s in (second or ms )

time_d = (t2_end.tv_sec-t2_start.tv_sec)*1000000 + t2_end.tv_usec - t2_start.tv_usec;
time_h = (t1_end.tv_sec-t1_start.tv_sec)*1000000 + t1_end.tv_usec - t1_start.tv_usec;
printf(“%d %lf %lf\n”,N,time_d,time_h);

You’ve not shown the code where (I assume) you use [font=“Courier New”]gettimeofday()[/font] to fill the [font=“Courier New”]struct timeval[/font]s. If that is what you do the value is in microseconds.

You’ve not shown the code where (I assume) you use [font=“Courier New”]gettimeofday()[/font] to fill the [font=“Courier New”]struct timeval[/font]s. If that is what you do the value is in microseconds.

thank’s for your reply

yes i use gettimeofday().

so the unit is microseconds.

i have other question please i would like know the meaning

of the line :

time_d = (t2_end.tv_sec - t2_start.tv_sec)*1000000 + t2_end.tv_usec - t2_start.tv_usec;

espicially difference between t2_end.tv_sec and t2_end.tv_usec

thank’s for your reply

yes i use gettimeofday().

so the unit is microseconds.

i have other question please i would like know the meaning

of the line :

time_d = (t2_end.tv_sec - t2_start.tv_sec)*1000000 + t2_end.tv_usec - t2_start.tv_usec;

espicially difference between t2_end.tv_sec and t2_end.tv_usec

[font=“Courier New”]struct timeval[/font] has two members: [font=“Courier New”]sec[/font] is the integer part of the time since midnight in seconds. [font=“Courier New”]usec[/font] is the fractional part, expressed in microseconds. So to combine both fields into one value, the difference of the [font=“Courier New”]sec[/font] field is multiplied by one million to turn it into mocroseconds, and then added to the microseconds part to give the final result.

[font=“Courier New”]struct timeval[/font] has two members: [font=“Courier New”]sec[/font] is the integer part of the time since midnight in seconds. [font=“Courier New”]usec[/font] is the fractional part, expressed in microseconds. So to combine both fields into one value, the difference of the [font=“Courier New”]sec[/font] field is multiplied by one million to turn it into mocroseconds, and then added to the microseconds part to give the final result.

thank you very much

the result is in µs

thank you very much

the result is in µs