Skip to content

Instantly share code, notes, and snippets.

@tony-o
Created December 10, 2020 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tony-o/22bb89f23c44bac271f2ac7a76da4721 to your computer and use it in GitHub Desktop.
Save tony-o/22bb89f23c44bac271f2ac7a76da4721 to your computer and use it in GitHub Desktop.
λ local:~$ raku -e 'use Bench; my @front = ^100; my @back = ^100; Bench.new.cmpthese(2_000_000, { pop => sub { @front.unshift(1); @front.pop() }, shift => sub { @back.push(1); @back.shift() }, });'
Benchmark:
Timing 2000000 iterations of pop, shift...
pop: 74.150 wallclock secs (66.918 usr 9.807 sys 76.724 cpu) @ 26972.511/s (n=2000000)
shift: 85.387 wallclock secs (77.559 usr 10.192 sys 87.750 cpu) @ 23422.720/s (n=2000000)
O-------O---------O------O-------O
| | Rate | pop | shift |
O=======O=========O======O=======O
| pop | 26973/s | -- | -55% |
| shift | 23423/s | 122% | -- |
O-------O---------O------O-------O
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment