There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

[TIP] Quickly benchmark commands using Perl

TIL that I can use Perl’s Benchmark module to time and compare the performance of different commands in an OS-agnostic way, ie as long as Perl is installed.

For example, to benchmark curl, wget and httpie you could simply run:


<span style="color:#323232;">$ perl -MBenchmark=:all 
</span><span style="color:#323232;">     -E </span><span style="color:#183691;">'$cmd_wget    = sub { system("wget  https://google.com > /dev/null 2>&amp;1") };'</span><span style="color:#323232;"> 
</span><span style="color:#323232;">     -E </span><span style="color:#183691;">'$cmd_curl    = sub { system("curl  https://google.com > /dev/null 2>&amp;1") };'</span><span style="color:#323232;"> 
</span><span style="color:#323232;">     -E </span><span style="color:#183691;">'$cmd_httpie  = sub { system("https https://google.com > /dev/null 2>&amp;1") };'</span><span style="color:#323232;"> 
</span><span style="color:#323232;">     -E </span><span style="color:#183691;">'$timeresult  = timethese(15, { "wget" => $cmd_wget, "curl" => $cmd_curl, "httpie" => $cmd_httpie });'</span><span style="color:#323232;"> 
</span><span style="color:#323232;">     -E </span><span style="color:#183691;">'cmpthese($timeresult)'
</span>

which on my old T530 produces:


<span style="color:#323232;">Benchmark: timing 15 iterations of curl, httpie, wget...
</span><span style="color:#323232;">
</span><span style="color:#323232;">      curl:  2 wallclock secs ( 0.00 usr  0.00 sys +  0.42 cusr  0.11 csys =  0.53 CPU) @ 28.30/s (n=15)
</span><span style="color:#323232;">    httpie:  8 wallclock secs ( 0.00 usr  0.01 sys +  4.63 cusr  0.79 csys =  5.43 CPU) @  2.76/s (n=15)
</span><span style="color:#323232;">      wget:  3 wallclock secs ( 0.00 usr  0.00 sys +  0.53 cusr  0.19 csys =  0.72 CPU) @ 20.83/s (n=15)
</span><span style="color:#323232;">    
</span><span style="color:#323232;">         Rate httpie   wget   curl
</span><span style="color:#323232;">httpie 2.76/s     --   -87%   -90%
</span><span style="color:#323232;">wget   20.8/s   654%     --   -26%
</span><span style="color:#323232;">curl   28.3/s   925%    36%     --
</span>

Very handy indeed ❤

palordrolap ,

See also: The shell's own times command (where available), and/or the external command time, which is the fore-runner of all of these.

Those won't run a command a number of times or provide a pretty table like Perl's benchmarker will, but if you want to roll your own, those would be the place to start.

(I'm a big fan of Perl, but know that not everyone's ready for it yet!)

  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines