Skip to content

Instantly share code, notes, and snippets.

@noqisofon
Forked from ww24/example.js
Created November 17, 2012 07:54
Show Gist options
  • Save noqisofon/4094116 to your computer and use it in GitHub Desktop.
Save noqisofon/4094116 to your computer and use it in GitHub Desktop.
Prime - 10万以下の素数を表示
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
@noqisofon
Copy link
Author

           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)

@noqisofon
Copy link
Author

うげっw コメント変ww

@noqisofon
Copy link
Author

               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