Calculating time of execution with time() function

前端 未结 5 1418
盖世英雄少女心
盖世英雄少女心 2020-12-07 06:12

I was given the following HomeWork assignment,

Write a program to test on your computer how long it takes to do nlogn, n2, n5, 2n, and n! additions

5条回答
  •  爱一瞬间的悲伤
    2020-12-07 06:50

    At least on Unix-like systems, time() only gives you 1-second granularity, so it's not useful for timing things that take a very short amount of time (unless you execute them many times in a loop). Take a look at the gettimeofday() function, which gives you the current time with microsecond resolution. Or consider using clock(), which measure CPU time rather than wall-clock time.

提交回复
热议问题