Created
September 4, 2016 11:13
-
-
Save lokeshh/cc7b428fda100dedb005067c01b355db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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