File: mybench.rb

package info (click to toggle)
libnarray-ruby 0.5.9-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 564 kB
  • ctags: 564
  • sloc: ansic: 4,620; ruby: 1,513; python: 70; makefile: 5
file content (31 lines) | stat: -rw-r--r-- 477 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'narray'

REPEAT = 100
ARRSZ = 1_000_000
T = (RUBY_VERSION<"1.8.0") ? Time : Process

def bench_array(type=Float)
  [ NArray.new(type,ARRSZ).indgen!,
    NArray.new(type,ARRSZ).indgen!  ]
end

def bench_float
  bench_array(Float)
end

def bench_int
  bench_array(Integer)
end

def bench_complex
  bench_array(Complex)
end

def bench_time(n=REPEAT)
  t1 = T.times.utime
   for i in 1..n
     yield
   end
  t2 = T.times.utime 
  puts " Time: %.2f sec\n\n" % [t2-t1]
end