So I'm making a program where I use sorts. In my output I'm trying to print the time it took and the relative # of copies and compares. I'm doing a switch in my main. The problem is I don't want to type the equation every time I use it for the time and #. So I put it before the switch, the problem is that it only outputs 0 for the time and the #'s
Well, you
- started the clock on line 6 ...
- and stopped the clock on line 7 ...
- and computers are pretty quick!
so is it really surprising that it records time zero?!
You have already computed all the timing variables etc BEFORE you did any sorts. Lines 18, 19, etc do nothing. They do NOT re-use equations.
Yea I thought about it being fast that's why I did microseconds. As far as the relative #'s, it works when I put the whole equation each time in each case but it doesn't when I put it before.
it works when I put the whole equation each time in each case but it doesn't when I put it before.
That's because start = high_resolution_clock::now(); is not an equation*, it's an assignment. Just writing start; does absolutely nothing. The compiler generates no code for that line.
If you want to change the value of a variable you have to assign to it.
* If it was an equation, you should be able to write
high_resolution_clock::now() = auto start;
and it should mean exactly the same. Yet, that's not valid C++.
I don't think you do understand, or you wouldn't be asking that. The same does apply to relComp and relCopies. Put them alone on a line and they will do ... nothing.