Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to measure basic, primitive operations in C++?

Tags:

c++

For a project I am supposed to measure the running time of basic primitive operations in C++ for the machine that I am using. It says this:

Write a program that determines the values of the timing parameters of (fetch, store, +, -, *, /, <, function call, function return, new, delete, and []) for the machine on which it is run.

fetch and store is:

a = b + 1

b and 1 are being "fetched" (and added together with +), and stored in a.

I've never done something like this before. Doing I need to use a clock method to calculate the running time? Should the code that I am timing be complex or simple? How many times should it be evaluated?

like image 926
template boy Avatar asked Nov 11 '22 02:11

template boy


1 Answers

I think this might be helpful. Personally I would make some loops with different number of iterations (starting from for example 10 and ending at 100 000). Similar to comparing sorting methods.

Ofc, if you need more complex method you can use performance hook mentioned before.

like image 119
Szczurson Avatar answered Nov 14 '22 23:11

Szczurson