Is my method of measuring running time flawed?

前端 未结 8 637
春和景丽
春和景丽 2021-02-05 12:14

Sorry, it\'s a long one, but I\'m just explaining my train of thought as I analyze this. Questions at the end.

I have an understanding of what goes into measuring runni

8条回答
  •  无人共我
    2021-02-05 12:43

    I think your first code sample seems like the best approach.

    Your first code sample is small, clean and simple and doesn't use any major abstractions during the test loop which may introduce hidden overhead.

    Use of the Stopwatch class is a good thing as it simplifies the code one normally has to write to get high-resolution timings.

    One thing you might consider is providing the option to iterate the test for a smaller number of times untimed before entering the timing loop to warm up any caches, buffers, connections, handles, sockets, threadpool threads etc. that the test routine may exercise.

    HTH.

提交回复
热议问题