Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- ----------
- Time taken: 0.38085579872131s
- Reps: 1000000
- Average time: 380ns
- ----------
- Time taken: 0.1891758441925s
- Reps: 1000000
- Average time: 189ns
- ]]
- function floorIt()
- local n = math.random()*2;
- return math.floor(n) == 0;
- end
- function almostZero()
- local n = math.random()*2;
- return n < 1e-2;
- end
- unitValue = {
- ms = 1e3;
- us = 1e6;
- ns = 1e9;
- }
- function secondsTo(unit, numSecs)
- return ""..math.floor(numSecs*unitValue[unit])..unit;
- end
- function timeTest(unit, f, reps, ...)
- local ti = tick();
- for i = 1, reps do
- f(...);
- end
- local t_total = tick() - ti;
- print('----------');
- print("Time taken: "..t_total.."s");
- print("Reps: " .. reps);
- print("Average time: "..secondsTo(unit, t_total/reps));
- end
- timeTest('ns', floorIt, 1000000);
- timeTest('ns', almostZero, 1000000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement