This question already has an answer here:
$ time ./Test
real 0m2.906s
user 0m2.887s
sys 0m0.017s
Here is the program code:
#include <iostream>
#include <map>
void func_a() {
std::map<int, int> m;
for (unsigned int i = 0; i < 10000; i++) {
m.insert(std::pair<int, int>(i, i));
}
}
void func_b() {
std::map<int, int> m;
for (unsigned int i = 0; i < 1000000; i++) {
m.insert(std::pair<int, int>(i, i));
}
}
int main() {
func_a();
func_b();
return 0;
}
If you take a look at the manpage (
man time
), it states:Basically though, the
user
time is how long your program was running on the CPU, and thesys
time was how long your program was waiting for the operating system to perform tasks for it. If you're interested in benchmarking,user + sys
is a good time to use.real
can be affected by other running processes, and is more inconsistent.