Skip to content

Instantly share code, notes, and snippets.

@samcv

samcv/time.nqp Secret

Last active July 11, 2018 11:15
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 samcv/9a65a586ea21b20def8efe4aaaab55de to your computer and use it in GitHub Desktop.
Save samcv/9a65a586ea21b20def8efe4aaaab55de to your computer and use it in GitHub Desktop.
Add a million keys to a hash, then delete every other, add them back. Then delete every 3rd, then add back... up to 6
my %hash;
my int $num := 1000000;
my int $i := 0;
while $i < $num {
nqp::bindkey(%hash, $i, 1);
$i := $i + 1;
}
my @array := (2, 3, 4, 5, 6);
for @array {
$i := 0;
while $i < $num {
nqp::deletekey(%hash, $i);
$i := $i + $_;
}
$i := 0;
while $i < $num {
nqp::bindkey(%hash, $i, 1);
$i := $i + $_;
}
}
my %hash;
my int $num = 1000000;
for ^$num -> $i {
%hash{$i} = 1;
}
my int $i;
my @array := (2, 3, 4, 5, 6);
for (2, 3, 4, 5, 6) -> $interval {
loop ($i = 0; $i < $num; $i += $interval) {
%hash{$i}:delete;
}
loop ($i = 0; $i < $num; $i += $interval) {
%hash{$i} = 1;
}
}
hash = {}
num = 1000000
for i in range(num):
hash[i] = 1
for j in (2,3,4,5,6):
for i in range(0, num, j):
del hash[i]
for i in range(0, num, j):
hash[i] = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment