Reputation: 3258
I'm trying out different languages to write command line programs, which of those are doing exactly the same thing. Now I'd like to know which one is the most performant. Is there a language-agnostic tool that can help me to measure both speed and memory consumption? It would be better if it is cross-platform. Thanks!
Upvotes: 0
Views: 133
Reputation: 364118
On any Unix system, time
a whole executable, perfect for command-line tools. Some implementations of time
, or other similar tools, print a memory high-water mark.
On Linux, perf stat ./my_executable
will time it (wall clock and total CPU time) and can show other metrics like branch mispredicts, cache misses, and other hardware performance-counter events. And also kernel software counters like page-faults, context-switches, and CPU migrations. (Helpful to notice interference from other processes, or for multi-threaded programs to notice actual effects.)
perf record ./my_executable
will do sample-based profiling to show hot spots. It has more options to take call-stack snapshots so you can find out which parent functions are actually responsible for making expensive function calls.
For some reason perf report
doesn't like to let you drill down to disassembly if it doesn't have debug symbols, probably because x86 machine code can't be disassembled backwards, only forwards from a known starting point. But it has lots of starting points and refuses to use them.
Assembly-language is basically language-agnostic, especially for ahead-of-time compiled binaries. In interpreted code, there aren't machine instructions that correspond to your source. In JIT-compiled code there are, but they only exist at runtime, not in a file anywhere.
Upvotes: 1