Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tcsh time and makefile time are significantly different

I'm seeing different behavior when running time in make and in terminal. I'm compiling multithreaded programs with OpenMP and pthread (separately) and timing them to compare their speedups with the sequential version of the program. However, when I run time a.out on terminal, I get 60+ seconds for each program, but within the makefile, I get less than 10 seconds for both. Additionally, the terminal time calculation takes less than 60 seconds to return, so I feel like it's lying to me.

What would be causing this? I originally thought maybe make and terminal are using different time functions, but apparently I don't have /usr/bin/time. Does make have a builtin time or something?

Edit: Yes, I know that user and sys in time are affected by the number of threads and can be greater than real, and that time is built in. My question is: why would running the same thing from different places (terminal and make in the same session) cause significant differences in the times returned? The two time outputs are not remotely close to each other.

like image 888
calccrypto Avatar asked Oct 19 '25 14:10

calccrypto


1 Answers

Almost all shells have time as builtin. I don't know how you call time, but you probably need to interpret the results from it differently depending on the shell.

I made an experiment with a program with 4 threads that waste some time:

$ cc -o foo foo.c && time ./foo

real    0m5.258s
user    0m18.805s
sys 0m0.061s
$ tcsh
% time ./foo
18.978u 0.062s 0:05.30 359.0%   0+0k 0+0io 0pf+0w

tcsh reports the user time first, then system time, then real time. Bash reports real time, user time, then system time. Those mean different things. Real time is the "wall clock" time, how much time has passed if you measured it with a stop watch. User time is cpu time you've used running your code in userland which is a total for all the cpus you've used.

like image 73
Art Avatar answered Oct 22 '25 04:10

Art