[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Is it supposed to be faster to call a C function than a Lua function when in Lua?
- From: Eric Wing <ewmailing@...>
- Date: Wed, 26 Jun 2013 22:30:31 -0700
I've been doing some performance benchmarks to quantify the cost of
crossing between scripting language to native code. I'm using Lua as
my theoretical ideal best performance case. I'm only looking at the
cost of the function call overhead, not the execution time of doing
stuff in the function.
One interesting thing came up I didn't expect. Calling a C function
that takes no parameters and returns no values is faster than calling
a Lua function with the same signature. On one of my test devices, the
call time was
0.167 microseconds per call calling to C
0.234 microseconds per call calling Lua
Passing a number and returning a number via C was:
0.235 microseconds per call
Is this the expected behavior? I know my simple arguments in this case
make things much easier, but I was always under the impression that
crossing the language bridge was much more expensive than staying in
the interpreter (i.e. you're only supposed to win if the stuff you do
in your function on the native side is computationally expensive
enough to overcome the cost of calling the function).
I am testing on iOS and Android (armv7) using Lua 5.1.5.
Here is a spreadsheet with my Lua data:
https://docs.google.com/spreadsheet/ccc?key=0AkOLZ2HKwMN2dDZDRm93Z1lpZXFtemlWVW5mNmRxVHc&usp=sharing
And here are my test code repositories:
https://github.com/ewmailing/CalloverheadBenchmarkLuaAndroid
https://github.com/ewmailing/CalloverheadBenchmarkLuaiOS
P.S. If anybody wants to drop in LuaJIT, I would love to see the numbers.
Thanks,
Eric
--
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/