Skip to content

Instantly share code, notes, and snippets.

@Bajena

Bajena/block8.rb Secret

Created April 23, 2020 20:18
Show Gist options
  • Save Bajena/aec7a4c8ac2e21f3bcd08c2e95699e1f to your computer and use it in GitHub Desktop.
Save Bajena/aec7a4c8ac2e21f3bcd08c2e95699e1f to your computer and use it in GitHub Desktop.
task :benchmark_inverse do
require "matrix_boost"
dim = 4
n = 1000000
puts "Benchmark inversion (dim = #{dim}, n = #{n})..."
m = Matrix.build(dim) { rand }
Benchmark.benchmark(Benchmark::CAPTION, 45, Benchmark::FORMAT, ">Ruby slower (%):") do |x|
r = x.report("Ruby matrix inverse:") { n.times { m.inverse } }
c = x.report("C matrix inverse:") { n.times { MatrixBoost.invert(m) } }
[r / c]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment