Skip to content

Instantly share code, notes, and snippets.

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 shyouhei/2407477 to your computer and use it in GitHub Desktop.
Save shyouhei/2407477 to your computer and use it in GitHub Desktop.
require 'benchmark'
a = Array.new(4096) { [rand(1 << 64), rand(1 << 64)] }
n = 1 << 32
Benchmark.bmbm do |x|
x.report do
a.collect do |b|
a.select do |c|
n >= Math.sqrt(
(b[0] - c[0]) ** 2 + (b[1] - c[1]) ** 2
)
end
end
end
end
Rehearsal ------------------------------------
88.860000 3.410000 92.270000 ( 92.315821)
-------------------------- total: 92.270000sec
user system total real
85.220000 3.690000 88.910000 ( 88.928956)
Rehearsal ------------------------------------
122.530000 0.340000 122.870000 (122.910743)
------------------------- total: 122.870000sec
user system total real
119.470000 0.050000 119.520000 (119.579139)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment