Skip to content

Instantly share code, notes, and snippets.

@cronin101
Created August 30, 2013 14:03
Show Gist options
  • Select an option

  • Save cronin101/6390188 to your computer and use it in GitHub Desktop.

Select an option

Save cronin101/6390188 to your computer and use it in GitHub Desktop.
Benchmark1
#!/usr/bin/env ruby
require './hadope'
require 'benchmark'
puts "Problem, mapping an addition (or two) to a large Array"
Hadope::set_device Hadope::CPU
input = (1..10_000_000).to_a
ruby = Benchmark.realtime {
last = input.map { |i| i + 1 }.map { |j| j + 1 }.last
puts "Ruby says last result is #{last}"
}
opencl = Benchmark.realtime {
last = input[Integers].map(i:'i + 1').map(j:'j + 1')[Fixnums].last
puts "OpenCL says last result is #{last}"
}
puts "Ruby: #{ruby.inspect}, OpenCL: #{opencl.inspect}"
=begin
λ HaDope git:(master) ✗ ./Benchmark.rb
Problem, mapping an addition (or two) to a large Array
Ruby says last result is 10000002
OpenCL says last result is 10000002
Ruby: 1.503207, OpenCL: 0.270248
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment