-2

I have a simple program that's supposed to sort a table, and measure the number of processor ticks needed to do it:

timePerRun = Stopwatch.StartNew();                                        
QuickSortLibrary.Quicksort.QuickSort(tabOfInts, 0, tabOfInts.Length-1);   
timePerRun.Stop();   

The only problem is that when I'm trying to sort a table of ~15 elements, I get 1-4 ticks. Is it possible that it happens so quickly, or the stopwatch only measures what happens in this method, not in the one that does actual sorting?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jarek N
  • 55
  • 9
  • 1
    that is measuring both. a table of 15 elements would be pretty quick to sort. – Daniel A. White Jan 10 '19 at 14:49
  • If you simply want to benchmark your program, just use something like [BenchmarkDotNet](https://benchmarkdotnet.org) and that's all. – Yurii N. Jan 10 '19 at 14:52
  • It's not about benchmarking, It's supposed to measure it and display the value. I was just confused that it did the entire sorting so quickly – Jarek N Jan 10 '19 at 14:54
  • 2
    a modern cpu can do billions of operations per second. `Ticks` is not a measurement of CPU cycles. – Daniel A. White Jan 10 '19 at 14:59
  • is the `QuickSortLibrary.Quicksort.QuickSort` call happening on the same thread or a separate thread? Is it a optimized release build or a a debug build? Is the data well randomly generated for sorting or is contrived for a faster execution of `QuickSortLibrary.Quicksort.QuickSort`? On a single threaded, debug build, with random data scenario, I highly doubt the call finishes in a single tick. On the other hand, a release build with contrived data, it is possible (I would guess) – Vikhram Jan 10 '19 at 14:59
  • https://stackoverflow.com/questions/956483/how-long-is-a-net-datetime-timespan-tick – Daniel A. White Jan 10 '19 at 15:00

1 Answers1

2

It is really possible that this happens so quickly. For so little elements, which all fit in the cache, it is a piece of joke for a contemporary CPU.

Nick
  • 4,787
  • 2
  • 18
  • 24