Last active
January 1, 2019 09:47
-
-
Save kojix2/9d22fecf8c7c5f304c2311f005b7ecc1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'numo/narray' | |
require 'cumo' | |
SIZE = 2000 | |
NUM = 1000 | |
Xumo = [Numo, Cumo] | |
Types = %i[UInt8 Int32 SFloat] | |
arithmetic = [ | |
'z = x + y', | |
'z = x - y', | |
'z = x * y', | |
'z = x / y' | |
] | |
Benchmark.bm 30 do |r| | |
Xumo.each do |xumo| | |
Types.each do |type| | |
narray = xumo.const_get(type) | |
x = narray.new(SIZE, SIZE).seq | |
y = narray.new(SIZE, SIZE).seq.reverse | |
x[x.eq 0] = 1 | |
y[y.eq 0] = 1 | |
arithmetic.each do |s| | |
str = x.class.to_s.ljust(16) + s | |
r.report str do | |
NUM.times do | |
eval(s) | |
end | |
end | |
end | |
end | |
end | |
x = Matrix.build(SIZE, SIZE) { |row, col| SIZE * row + col } | |
y = Matrix.build(SIZE, SIZE) { |row, col| SIZE * (SIZE - 1 - row) + (SIZE - 1 - col) } | |
arithmetic.each do |s| | |
str = x.class.to_s.ljust(16) + s | |
r.report str do | |
NUM.times do | |
eval(s) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment