Skip to content

Instantly share code, notes, and snippets.

@yamaguchi1024
Created December 18, 2015 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yamaguchi1024/621c1597fdcd50e300d9 to your computer and use it in GitHub Desktop.
Save yamaguchi1024/621c1597fdcd50e300d9 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
class Matrix
MEMSIZE=[16, 32, 64, 128, 256, 512, 1024]
def run
print "N,seconds,Mop/s\n"
MEMSIZE.each { |n|
a=Array.new(n){Array.new(n)}
b=Array.new(n){Array.new(n)}
c=Array.new(n){Array.new(n)}
print n.to_s()+","
(0..n-1).each { |i|
(0..n-1).each { |j|
a[i][j]=(i*j+2*j).to_f()
b[i][j]=(i*2+j).to_f()
}
}
start_time=Time.now.to_f()
n.times do |i|
n.times do |j|
n.times do |s|
c[i][j]=a[i][s]*b[s][i]
end
end
end
end_time=Time.now.to_f()
elapsed_time=end_time-start_time
print elapsed_time.to_s()+","
mops=0.000001*n**3/elapsed_time
print mops.to_s()+"\n"
}
end
end
sp=Matrix.new()
sp.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment