-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbenchmark.lua
69 lines (57 loc) · 3.41 KB
/
benchmark.lua
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
local narray = require("array")
local bcount = 200
local bshape = {100,100,100}
local bshape1 = {100,100,100,1}
local btype = narray.int32
local ta = narray.create(bshape, narray.int32)
local ta1 = narray.create(bshape1, narray.int32)
local taf = narray.create(bshape, narray.float32)
local tb = narray.create(bshape, narray.int32)
local tb1 = narray.create(bshape1, narray.int32)
local tc = narray.create(bshape, narray.int32)
local tc1 = narray.create(bshape1, narray.int32)
print("\nBenchmarks for array shape = ".. helpers.to_string(bshape) ..", type = " .. tostring(btype) .. "\n")
helpers.benchmark(function()
math.randomseed(31415927)
local rand = narray.randint(0,100000,{1000000})
helpers.benchmark(function() rand:sort() end, 1, "sort 1000000 integers")
local rand = narray.randint(0,100000,{1000000})
helpers.benchmark(function() rand:argsort() end, 1, "argsort 1000000 integers")
local rand = narray.rand({1000000})
helpers.benchmark(function() rand:sort() end, 1, "sort 1000000 floats")
local rand = narray.rand({1000000})
helpers.benchmark(function() rand:argsort() end, 1, "argsort 1000000 floats")
helpers.benchmark(function() local blubb = narray.create(bshape, btype) end, bcount, "allocate array")
helpers.benchmark(function() ta:add(3) end, bcount, "add constant")
helpers.benchmark(function() for pos in ta:coordinates() do end end, bcount, "coordinates (iterator)")
helpers.benchmark(function() for val in ta:values() do end end, bcount, "values (iterator)")
helpers.benchmark(function() for pos, val in ta:pairs() do end end, bcount, "pairs (iterator)")
helpers.benchmark(function() ta1:add(3) end, bcount, "add constant - singleton")
helpers.benchmark(function() ta:add(tb) end, bcount, "add array")
helpers.benchmark(function() ta1:add(tb1) end, bcount, "add array - singleton")
helpers.benchmark(function() ta:sub(tb) end, bcount, "sub array")
helpers.benchmark(function() ta:sub(1) end, bcount, "sub constant")
helpers.benchmark(function() ta:eq(7) end, bcount, "eq(constant)")
helpers.benchmark(function() ta:eq(tc) end, bcount, "eq(array)")
helpers.benchmark(function() taf:eq(7) end, bcount, "eq(constant) for float array")
helpers.benchmark(function() ta:neq(tc) end, bcount, "neq(array)")
helpers.benchmark(function() ta:neq(7) end, bcount, "neq(constant)")
helpers.benchmark(function() taf:neq(7) end, bcount, "neq(constant) for float array")
helpers.benchmark(function() ta:all() end, bcount, "all() test array")
helpers.benchmark(function() ta:any() end, bcount, "any() test array")
helpers.benchmark(function() ta:assign(0) end, bcount, "assign element")
helpers.benchmark(function() ta:assign(tb) end, bcount, "assign array")
helpers.benchmark(function() ta:nonzero() end, bcount, "nonzero")
helpers.benchmark(function() narray.rand(bshape) end, bcount, "rand - allocate random floats")
helpers.benchmark(function() narray.randint(10,100,bshape) end, bcount, "randint - allocate random int")
ta:assign(3)
local lut = narray.create({10}, narray.uint8)
lut:set(0,0)
lut:set(1,10)
lut:set(2,20)
lut:set(3,30)
helpers.benchmark(function() ta:lookup(lut) end, bcount, "lookup(lut)")
local res = ta:nonzero()
helpers.benchmark(function() ta:setCoordinates(res,0) end, bcount, "setCoordinates")
helpers.benchmark(function() ta:getCoordinates(res) end, bcount, "getCoordinates")
end, 1, "------- COMBINED EXECUTION TIME --------")