2 ms·
Long time ago, I've did some experiments with luajit and branching (well more like the CPU). It was based on this article: http://igoro.com/archive/fast-and-slo
by malkia 11y ago
Long time ago, I've did some experiments with luajit and branching (well more like the CPU). It was based on this article: http://igoro.com/archive/fast-and-slow-if-statements-branch-prediction-in-modern-processors/ http://igoro.com/archive/fast-and-slow-if-statements-branch-...
https://raw.githubusercontent.com/malkia/ufo/master/samples/bench/badif.lua https://raw.githubusercontent.com/malkia/ufo/master/samples/...
local ffi = require("ffi")
local band = bit.band
local function test(n, m)
local count = 0; for i=1, n do if band(i, m)==0 then count = count + 1 end end return count
end
local function timeit(m)
local t = os.clock()
test(0xFFFFFFF,m)
local t = os.clock() - t
print(string.format("%08X",m),t)
end
timeit(0x80000000)
timeit(0xffffffff)
timeit(1)
timeit(3)
timeit(2)
timeit(4)
timeit(8)
timeit(16)
--[[
-- This is on OSX 10.7.2 MBP 2008 Jan build
./luajit samples/badif.lua
80000000 14.067395
FFFFFFFF 20.252955
00000001 13.497108
00000003 17.337942
00000002 14.142266
00000004 14.221376
00000008 14.42377
00000010 14.708237
--]]
Results now - 2015 (again Macbook OSX, much better than before and also luajit 2.0.4):
80000000 0.247822
FFFFFFFF 1.253168
00000001 0.664586
00000003 0.974336
00000002 0.676823
00000004 0.679609
00000008 0.675207
00000010 0.673961
without jit, just interpretter (pretty much the same results):
$ src/luajit -joff ~/badif.lua
80000000 3.329909
FFFFFFFF 3.553143
00000001 3.440378
00000003 3.484646
00000002 3.424834
00000004 3.424539
00000008 3.616981
00000010 3.598598