Skip to content

Instantly share code, notes, and snippets.

@lokeshh
Created September 4, 2016 11:13
Show Gist options
  • Save lokeshh/cc7b428fda100dedb005067c01b355db to your computer and use it in GitHub Desktop.
Save lokeshh/cc7b428fda100dedb005067c01b355db to your computer and use it in GitHub Desktop.
require 'benchmark'
require 'matrix'
require 'nmatrix'
class Matrix
public :"[]=", :set_element, :set_component
end
m = Matrix.zero 1000 ;
n = NMatrix.new [1000, 1000], [0]*10**6
Benchmark.bm do |x|
x.report "Matrix getter" do
(10**7).times { m[555, 555] }
end
x.report "NMatrix getter" do
(10**7).times { n[555, 555] }
end
x.report "Matrix setter" do
(10**7).times { m[555, 555] = 100 }
end
x.report "NMatrix setter" do
(10**7).times { n[555, 555] = 100 }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment