Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function benchmark()
- local N = 10000000
- local k = 2
- local time_intervals = {}
- for j = 1, 2*k-1 do
- local two48 = 281474976710656 -- 2^48
- local x
- local clk0 = os.clock()
- for n = 1, N do
- x = two48
- % 281633765821878
- % 281861755493504
- % 140964708094569
- % 70513943648087
- % 23510499215727
- % 23530713002525
- % 7844914056857
- % 7845031723743
- % 7847893636219
- % 7849196854410
- % 2616787772181
- % 2616800002690
- % 2617789799177
- % 1309268885363
- % 654833271837
- % 655267877209
- % 327691649351
- % 327890975757
- % 109326241594
- % 54671377442
- % 18228208084
- % 6077944839
- % 3039188803
- --~ This sequence of constants was generated by the following code:
- --~ local x = 2^48
- --~ repeat
- --~ local factor = math.random(3)
- --~ local low = math.ceil(x / factor)
- --~ local high = math.floor(x / (factor - 0.001))
- --~ x = low + math.random(high - low)
- --~ print('% '..x)
- --~ until x < 2^32
- end
- time_intervals[j] = os.clock() - clk0
- end
- -- get median time
- table.sort(time_intervals)
- print('CPU seconds for integer modulo:', time_intervals[k])
- time_intervals = {}
- for j = 1, 2*k-1 do
- local two48 = 281474976710656.0 -- 2^48
- local x
- local clk0 = os.clock()
- for n = 1, N do
- x = two48
- % 281633765821878.0
- % 281861755493504.0
- % 140964708094569.0
- % 70513943648087.0
- % 23510499215727.0
- % 23530713002525.0
- % 7844914056857.0
- % 7845031723743.0
- % 7847893636219.0
- % 7849196854410.0
- % 2616787772181.0
- % 2616800002690.0
- % 2617789799177.0
- % 1309268885363.0
- % 654833271837.0
- % 655267877209.0
- % 327691649351.0
- % 327890975757.0
- % 109326241594.0
- % 54671377442.0
- % 18228208084.0
- % 6077944839.0
- % 3039188803.0
- end
- time_intervals[j] = os.clock() - clk0
- end
- -- get median time
- table.sort(time_intervals)
- print('CPU seconds for floating point modulo:', time_intervals[k])
- end
- benchmark()
Advertisement
Add Comment
Please, Sign In to add comment