dibyendumajumdar / ravi

Ravi is a dialect of Lua, featuring limited optional static typing, JIT and AOT compilers
http://ravilang.github.io/
Other
1.16k stars 60 forks source link

Compiling with CMake is slower that with make #206

Closed mingodad closed 3 years ago

mingodad commented 3 years ago

Just updated my clone of this project and testing ravi build from "make" at the root folder and with cmake in a build folder and testing with the script shown bellow the one done with "make" is more than twice as fast with CMake:

local function fib(n: integer)
    if (n < 2) then 
    return 1
    else
    return fib(n-2) + fib(n-1)
    end
end

print(fib(32))

Output:

/usr/bin/time ravi/src/ravi fibonacci.ravi 
3524578
0.24user 0.00system 0:00.25elapsed 99%CPU (0avgtext+0avgdata 2748maxresident)k
0inputs+0outputs (0major+123minor)pagefaults 0swaps

/usr/bin/time ravi/build/ravi fibonacci.ravi
3524578
0.77user 0.00system 0:00.78elapsed 99%CPU (0avgtext+0avgdata 3492maxresident)k
0inputs+0outputs (0major+146minor)pagefaults 0swaps
dibyendumajumdar commented 3 years ago

Hi, did you specify the build type in CMake? Perhaps it was a debug build? It would be useful to see an example compiler output from:

VERBOSE=1 make

dibyendumajumdar commented 3 years ago

Although the test is so short it might be just noise

dibyendumajumdar commented 3 years ago

By default if you don't specify the build type it doesn't use optimizer flags:

cmake ..

In verbose make output:

[ 21%] Building C object CMakeFiles/libravinojit_static.dir/src/lparser.c.o
/usr/bin/cc -DLUA_USE_LINUX=1 -I/home/xxx/github/ravi/include -march=native -o CMakeFiles/libravinojit_static.dir/src/lparser.c.o -c /home/xxx/github/ravi/src/lparser.c

So to get optimized builds, please set build type like so:

cmake -DCMAKE_BUILD_TYPE=Release ..
mingodad commented 3 years ago

Thank you ! Now ravi built with CMAKE is only 25% slower than ravi made with cmake. Is this the expected result ?

/usr/bin/time ravi-cmake fibonacci.ravi 
3524578
0.32user 0.00system 0:00.32elapsed 99%CPU (0avgtext+0avgdata 2880maxresident)k
8inputs+0outputs (0major+137minor)pagefaults 0swaps

/usr/bin/time rav-makei fibonacci.ravi 
3524578
0.25user 0.00system 0:00.26elapsed 97%CPU (0avgtext+0avgdata 2704maxresident)k
904inputs+0outputs (3major+124minor)pagefaults 0swaps
dibyendumajumdar commented 3 years ago

You shouldn't see any difference - but it may be that the optimizer flags are different. The make build uses -O2. CMake build in my host used -O3.

Also the test you are running isn't big enough to be conclusive.

dibyendumajumdar commented 3 years ago

Some other factors:

The make build doesn't link in the JIT backend. The CMAKE build does unless you disable it.