time command quick reference
← back to notes
> time ./app
./app 5.84s user 0.10s system 100% cpu 5.903 total
Command output meaning
| Field (example output) | Meaning | Interpretation / Gotchas | Benchmarking Notes |
|---|---|---|---|
| user (5.84s) | CPU time spent executing in user mode (your program's code, not the kernel) | Pure computation time — math, loops, data processing. Doesn't include I/O or system calls | High value means CPU-bound workload. Optimize algorithm or parallelize if possible |
| system (0.10s) | CPU time spent in kernel mode handling system calls | Usually low. High values indicate frequent I/O, syscalls, or context switches | If this rises significantly, profile with strace or perf to find syscall hotspots |
| cpu (100%) | Percentage of a single CPU utilized during the wall-clock run | 100% means fully using one core; >100% means multi-core usage | (user + sys)/real × 100 gives CPU utilization. Over 100% → parallel processing |
| total / real (5.903s) | Wall-clock (elapsed) time from start to finish | Includes waiting, scheduling, I/O, and all other delays | Best measure of how long it actually took. High real vs low user+sys → program was blocked or waiting |
Useful notes for interpretation
| Scenario / Metric | Meaning | Interpretation / Gotchas | Benchmarking Notes |
|---|---|---|---|
| user + system (≈5.94s) | Total CPU time consumed across all cores | Can exceed real time on multi-core systems |
(user+sys)/real ratio = CPU efficiency or parallelism. Here ≈ 1.006 → perfect single-core utilization |
| High real vs low user+sys | Program waited (I/O bound, sleep, blocked) | E.g., 1.00s real, 0.01s user, 0.01s sys → waiting 98% of the time | Investigate disk, network, or synchronization issues |
| High user vs low system | Heavy compute workload, minimal I/O | E.g., 5.84s user, 0.10s sys → typical of compute-heavy jobs | Optimize CPU code paths, use SIMD, JIT, or multi-threading |
| High system vs user | Kernel overhead dominating | E.g., 0.5s user, 3s sys → syscall-heavy or I/O-thrashing | Optimize file access, reduce context switches, batch I/O |
| CPU ≈ 100% and user ≫ sys | CPU fully utilized on one core, efficient use | Example matches this case | Good benchmark baseline; shows program is CPU-bound and well-utilized |
| Multicore gotcha | user+sys > real by large margin | Parallel workload summing per-core CPU time | Use htop or /usr/bin/time -v to confirm multi-core behavior |
| Benchmarking tip | Don't trust single runs | CPU scaling, caching, and OS noise cause variance | Run several times, average results, and isolate the environment |