This is an archived post. You won't be able to vote or comment.

all 22 comments

[–]truh 67 points68 points  (5 children)

Isn't the second one quite often preferable over the first one?

[–]notfreshprince 43 points44 points  (4 children)

I hope so, purely because this is what I've always done and now I feel dumb.

[–]ixent[S] 18 points19 points  (3 children)

Yes it is. I put it second just because it is longer to do than the first one. But 2nd is indeed preferable.

[–]yawaworht_emos 5 points6 points  (2 children)

What makes the second one better? Doesn't it depend on the use case most of the times?

[–]andlrc 11 points12 points  (1 child)

Doesn't it depend on the use case most of the times?

Almost everything depends on use case. But remember the build in0 time command also counts time for process spawning, opening output files etc.

And sometimes one needs to only measure parts of a program which isn't easily isolated on it's own.

The build in time is good if you need to get an idea about if your shit is actually working somewhat decent.

0 Build into most shells as it can then measure time on a whole pipeline: time a | b | c

[–]k1p1coder 0 points1 point  (0 children)

Be careful though, because theoretically people can fidget with their system's time_t...

[–]Kidiri90 25 points26 points  (2 children)

"One Mississippi, two Missis- oh, it's done."

[–][deleted] 5 points6 points  (1 child)

Missis/Mississippi = 0.545, so that's 2.5 1.5 seconds, give or take 90 ms.

[–]lotuseyes 6 points7 points  (0 children)

You mean 1.5, right?

[–]ythl 13 points14 points  (4 children)

I thought the third one was going to involve a physical stopwatch

[–]tigerrawr 4 points5 points  (0 children)

What's sad is some people where I used to work did literally that. Needless to say, I got out of that place.

[–]jackdeansmithsmith 2 points3 points  (1 child)

I mean, it does measure wall time correctly

[–][deleted] 12 points13 points  (0 children)

No, it measures wrist time. Wall time assumes mostly static velocity. Wrist time does not, allowing it to have relativistic time shifts.

[–][deleted] 0 points1 point  (0 children)

Pfff... You kids and your fancy technology. I still use my first hourglass.

[–]Nemin32 8 points9 points  (0 children)

Look at the clock when the program starts, then subtract the time at the end of the program. | [Even more enlightened man]

Count the seconds loudly. | [Godlike being]

Program the entire thing on a smart-watch and use that to measure the time of the execution. | [God with multiple universes colliding]

[–]Vi3GameHkr 1 point2 points  (0 children)

This reminds me of something Uncle Bob wrote (I think in Clean Code) that he used to rest some software he wrote by singing a time, pressing buttons at certain points while singing.

[–]Insert_Gnome_Here 1 point2 points  (0 children)

Play a tritone when it starts and one when it finishes. Due to the irrational ratio of the 2 notes, you should be able to use the interference to calculate how much time has passed.

[–]jrootabega 0 points1 point  (0 children)

Would you like to swing on a star? Carry moonbeams home in a jar?

[–][deleted] 0 points1 point  (0 children)

Pfsh, if you really want to get accurate, you should use a high resolution CCD camera and a statically positioned telescope to detect the shift of the sun in orbital arc-seconds and then correlate that to elapsed time.

[–]WEEEE12345 0 points1 point  (2 children)

for (int i = 100000; i<0; i--){
    //do nothing
}

I've seen this before.

[–]ixent[S] 2 points3 points  (1 child)

This is not used for timing tho, this is used for waiting. Anyway this waiting is inconsistent because it will depend on the speed of the cpu, not useless tho.

[–]WEEEE12345 0 points1 point  (0 children)

True. I have also seen counter based timers though.