Created
July 7, 2021 15:29
-
-
Save gfldex/962e83b4a0b76c65960711d30a294210 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub prefix:<♥>(&c) { | |
sub avg(@a) { @a.sum / +@a } | |
state %run-times; | |
LEAVE %run-times{&c.WHY}.push: (now - ENTER now); | |
END { say .key, ‚: ‘, .value »~» ‚s‘, ‚ avg: ‘,.value.&avg ~ ‚s‘ for %run-times } | |
c | |
} | |
for ^5 { | |
#| grep | |
♥ { say sum (^100_000).grep: *.is-prime; } | |
#| do for | |
♥ { say sum do for ^100_000 { .&next if .is-prime; } } | |
#| eager for | |
♥ { say sum eager for ^100_000 { .&next if .is-prime; } } | |
#| gather | |
♥ { say sum gather for ^100_000 { .take if .is-prime; } } | |
my \a = lazy gather for ^100_000_000 { .take if .is-prime; } | |
my \b = lazy for ^100_000_000 { .&next if .is-prime; } | |
#| lazy gather | |
♥ { say sum a[^100_000]; } | |
#| lazy for | |
♥ { say sum b[^100_000]; } | |
} |
tony-o
commented
Jul 7, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment