1
0
Fork
You've already forked shell-timeit
0
Timeit for shell commands
  • Python 79.9%
  • Shell 15.7%
  • Makefile 4.4%
Oliver Gerlich abe94117e0 Makefile: run pylint during "make check"
There are still warnings left in the code (which are ignored for now, using
the pylintrc_for_autocheck file); but let's enable pylint already to avoid
introducing new warnings.
2025年03月02日 21:54:40 +01:00
__snapshots__ tests: add test case "test_usage_error_output" 2025年03月02日 21:54:40 +01:00
.gitignore automatically set up Python environment before running tests or checks 2025年02月22日 11:43:30 +01:00
dd.json add very basic automatic test 2025年02月17日 22:28:45 +01:00
git-timeit git-timeit: fix Shellcheck warnings 2025年02月17日 22:28:45 +01:00
Makefile Makefile: run pylint during "make check" 2025年03月02日 21:54:40 +01:00
pylintrc_for_autocheck Makefile: run pylint during "make check" 2025年03月02日 21:54:40 +01:00
README.md README: update link from Python 2 to 3 2025年02月22日 17:27:35 +01:00
requirements-dev.txt requirements-dev.txt: add pylint 2025年02月23日 18:42:17 +01:00
requirements.txt move development dependencies into separate requirements-dev.txt 2025年02月22日 11:43:30 +01:00
test_shell_with_approvals.py tests: add test case "test_usage_error_output" 2025年03月02日 21:54:40 +01:00
timeit timeit: fix "consider-using-f-string" pylint warnings 2025年03月02日 21:54:40 +01:00
umlauts.json tests: add actual UTF-8 bytes to test data 2025年03月02日 21:54:40 +01:00
UNLICENSE add UNLICENSE file to put project into public domain 2016年12月13日 00:23:56 +01:00

shell-timeit

timeit runs a shell command multiple times, measures the execution time of each run, and prints the min/max/average times. It can also collect results in a file and create a diagram of all collected results.

Shell Timeit was inspired by the Python Timeit module.

Example

Run dd for in-memory copying with different block sizes:

  • each size is tested five times (-r 5) instead of the default of three times
  • the command is executed as shell command to allow redirecting output to /dev/null (-s)
  • results are written to dd.json (-f dd.json)
  • a comment is added for every test (-m ...)
  • results are afterwards turned into a diagram (-o dd.png)
for s in 1 2 5 10 20 50 100 200 500 1000 2000 5000 10000 20000 50000; do
 echo "testing with bs="$s"kB"
 timeit -r 5 -s -f dd.json -m "block size: $s kB" "dd if=/dev/zero of=/dev/null bs=$s"kB" count=$((1000000/$s)) >/dev/null 2>&1"
done
timeit -f dd.json -o dd.png

Result:

dd.json diagram

The bars show the lowest execution time; the small dots are the results of each single run.

The diagram displays lowest time prominently because this is the fastest time that was achievable with the specified settings; the higher values just indicate that something interfered with the run.

By default the diagram shows "wallclock seconds", ie. elapsed time, and also system and user CPU time. Other types of measurement can be displayed by specifying the measurement name before the diagram output file name, separated by "=". Multiple measurements can be displayed in a single diagram by listing their names separated by ",". Measurement values can be stacked by separating their names with "+".

Hence, the default diagram style can also be achieved like this:
timeit -f dd.json -o wallclock,ru_utime+ru_stime=dd.png

For a list of available measurement names, refer to the documentation of Python resource module or the getrusage(2) man page.

Alternative Tools

Similar to git-timeit: