Skip to content

Instantly share code, notes, and snippets.

@Kaiepi
Created December 17, 2022 17:21
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 Kaiepi/937162e3ca66cc1aa0d513436a33a080 to your computer and use it in GitHub Desktop.
Save Kaiepi/937162e3ca66cc1aa0d513436a33a080 to your computer and use it in GitHub Desktop.
use v6;
use Gauge;
# This is the benchmark in question:
#
# $ raku bench.raku --forever ndo-store-re-barely
#
# Other ndo-store-re-* benchmarks may or may not work, but perform fewer iterations in comparison.
my constant $VALUES = ^10_000;
my constant @VALUES = eager $VALUES;
my constant @SLIPPY = eager Slip.from-iterator: $VALUES.iterator;
my constant @RELIST = eager List.from-iterator: [$VALUES].iterator;
my constant @RECONT = eager [$VALUES];
my constant @NDDIMS = my @[10,2,5,100];
my constant @NDINTS = my int @[10,2,5,100];
my constant @NDOBJS = eager 0 xx 100 xx 5 xx 2 xx 10;
my constant @CASES =
<imm-from-iter>
=> { List.from-iterator: $VALUES.iterator },
<mut-from-iter>
=> { Array.from-iterator: $VALUES.iterator },
<mut-from-list>
=> { Array.from-list: @VALUES },
<imm-new-create>
=> { List.new },
<imm-new-finish>
=> { List.new: @SLIPPY },
<mut-new-create>
=> { Array.new },
<mut-new-shaped>
=> { Array.new: :shape(1,) },
<sub-new-create>
=> { Array[Any].new },
<sub-new-shaped>
=> { Array[Any].new: :shape(1,) },
<nat-new-create>
=> { array[int].new },
<nat-new-shaped>
=> { array[int].new: :shape(1,) },
<mut-clone>
=> { @RECONT.clone },
<imm-store-in-lazily>
=> { List.CREATE.STORE: $VALUES.lazy, :INITIALIZE },
<imm-store-in-finish>
=> { List.CREATE.STORE: $VALUES, :INITIALIZE },
<imm-store-re-finish>
=> { @RELIST.STORE: $VALUES },
<mut-store-in-lazily>
=> { Array.CREATE.STORE: $VALUES.lazy },
<mut-store-in-finish>
=> { Array.CREATE.STORE: $VALUES },
<ndo-store-re-shaped>
=> { @NDDIMS.STORE: @NDDIMS, :INITIALIZE },
<ndo-store-re-native>
=> { @NDDIMS.STORE: @NDINTS, :INITIALIZE },
<ndo-store-re-barely>
=> { @NDDIMS.STORE: @NDOBJS.iterator, :INITIALIZE },
<ndo-store-re-finish>
=> { @NDDIMS.STORE: @NDOBJS, :INITIALIZE };
my constant %CASES = @CASES;
only USAGE {
put 'To run the complete suite:';
put "$*EXECUTABLE-NAME $*PROGRAM-NAME";
put 'To run individual benchmarks:';
put "$*EXECUTABLE-NAME $*PROGRAM-NAME $_" for @CASES.map: *.key;
}
proto MAIN(|) {*}
multi MAIN(Str:D $name where %CASES, Bool:D :forever($)! where ?*) {
map *.finish, Thread.start({ Gauge(%CASES{$name}).poll(1).throttle(29).produce(&max).map(*.put) }) xx 4
}
multi MAIN(Str:D $name where %CASES) {
Gauge(%CASES{$name}).poll(1).throttle(29).produce(&max).rotor(8 => -7).map({ $_[0] if [==] $_ }).head.put
}
multi MAIN {
for @CASES -> Pair:D (:key($case), :value($)) {
print "$case: ...";
put "\r$case: ", await benchmark $case;
print "cooling...";
sleep 300;
print "\r";
}
}
only benchmark(Str:D $case --> Supply:D) {
supply given Proc::Async.new: $*EXECUTABLE-NAME, $*PROGRAM-NAME, $case {
whenever $^process.stdout.lines.head {
emit val $^line;
}
whenever $^process.stderr.lines {
note $^line;
}
whenever $^process.start {
done;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment