mirror of
https://github.com/lune-org/lune.git
synced 2025-04-03 01:50:55 +01:00
Fix benchmark code and add C level result (#243)
This commit is contained in:
parent
90c0987754
commit
80a7497583
3 changed files with 26 additions and 3 deletions
|
@ -64,6 +64,11 @@ Command: `cargo run --profile=release run tests/ffi/benchmark/external_call`
|
|||
|
||||
> Commit: ddf0c4c
|
||||
|
||||
**C**
|
||||
|
||||
- Device1-Linux-PVE: 0.001949 (sec)
|
||||
> gcc (GCC) 14.2.1 20240910
|
||||
|
||||
**LuaJit ffi**
|
||||
|
||||
Command: `luajit tests/ffi/benchmark/external_call/luajit.lua`
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
local ffi = require("@lune/ffi")
|
||||
local lib = require("../../utility/compile")("./tests/ffi/benchmark/external_call/lib.c")
|
||||
local lib = require("../../utils/compile")("./tests/ffi/benchmark/external_call/lib.c")
|
||||
local process = require("@lune/process")
|
||||
local c = ffi.c
|
||||
local BENCH_SCALE: number = tonumber(process.env.BENCH_SCALE) or 1000000
|
||||
|
||||
-- Get clock provider
|
||||
local procClock = require("../../utility/proc_clock")
|
||||
local procClock = require("../../utils/proc_clock")
|
||||
local before, after = procClock.newBox()
|
||||
local getClock = procClock.getClock
|
||||
|
||||
|
@ -22,6 +22,10 @@ for i = 1, BENCH_SCALE do
|
|||
end
|
||||
getClock(after)
|
||||
|
||||
print(procClock.getOffset(before, after))
|
||||
print("lune-std-ffi: " .. procClock.getOffset(before, after))
|
||||
local result = c.int:readData(a)
|
||||
assert(result == BENCH_SCALE, `bench_add failed. result expected {BENCH_SCALE}, got {result}`)
|
||||
|
||||
local cSideTime = ffi.box(ffi.f64.size)
|
||||
c.fn({}, ffi.f64):callable(lib:find("c_test"))(cSideTime)
|
||||
print("C level: " .. ffi.f64:readData(cSideTime))
|
||||
|
|
14
tests/ffi/benchmark/external_call/lib.c
vendored
14
tests/ffi/benchmark/external_call/lib.c
vendored
|
@ -1,4 +1,18 @@
|
|||
#include <time.h>
|
||||
|
||||
int add(int a, int b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
double c_test() {
|
||||
clock_t before = clock();
|
||||
|
||||
int a = 0;
|
||||
for (int i=0; i<1000000; i++) {
|
||||
a = add(a, 1);
|
||||
}
|
||||
|
||||
clock_t after = clock();
|
||||
|
||||
return (double)(after - before) / CLOCKS_PER_SEC;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue