-
-
Save noqisofon/4094116 to your computer and use it in GitHub Desktop.
Prime - 10万以下の素数を表示
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
require 'benchmark' | |
Benchmark.bm( 8 ) do |reportor| | |
reportor.report( "1000: " ) { | |
primes = [] | |
1000.times do |x| | |
x += 1 | |
if x != 1 and primes.all? { |y| x % y != 0 } then | |
primes << x | |
#p x | |
end | |
end | |
} | |
reportor.report( "10000:" ) { | |
primes = [] | |
10000.times do |x| | |
x += 1 | |
if x != 1 and primes.all? { |y| x % y != 0 } then | |
primes << x | |
#p x | |
end | |
end | |
} | |
reportor.report( "100000:" ) { | |
primes = [] | |
100000.times do |x| | |
x += 1 | |
if x != 1 and primes.all? { |y| x % y != 0 } then | |
primes << x | |
#p x | |
end | |
end | |
} | |
end |
うげっw コメント変ww
user system total real
1000: 0.000000 0.000000 0.000000 ( 0.003194)
10000: 0.140000 0.000000 0.140000 ( 0.134306)
100000: 7.770000 0.000000 7.770000 ( 7.775869)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1000: 0.000000 0.000000 0.000000 ( 0.003194)
10000: 0.140000 0.000000 0.140000 ( 0.134306)
100000: 7.770000 0.000000 7.770000 ( 7.775869)