0

in C/C++ we have a function clock() for keeping the current CPU clock for counting the time of execution programs:

t1 = clock()
for(...)
  for(...)
t2 = clock()
printf (t2 - t1)

but how I can do it in C#? I know there is some codes:

long t1 = stopwatch.startnow()
for(...)
  for(...)
t1.stop()
sum = t1.elapsedticks;

The problem is, that when I run codes in C, I see about 20 ticks, but when I run the same code in C#, I see about 60000 ticks. Please tell me that is it OK or not? Is my solution is true? Thanks a lot.

Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321
  • It is ok.. because C# a high level programming language and C/C++ is low programming languag.. – Mohamad Shiralizadeh Dec 13 '15 at 07:28
  • It's almost definitely to do with what you've got in your for loops (the part you've omitted) – Rob Dec 13 '15 at 07:39
  • Side note: make sure that "ticks" are the same between C/C#... Also common problem with such benchmarks is inlining/dead code elimination performed by C/C++ compilers - there is a good chance you've measured length of empty operation in you C sample code. – Alexei Levenkov Dec 13 '15 at 08:04

0 Answers0