Skip to content

Commit

Permalink
Add windows benchmark result (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwreey committed Oct 22, 2024
1 parent 886d555 commit b442ba7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
23 changes: 19 additions & 4 deletions tests/ffi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,44 @@ bench_scale = 1000000
Command: `cargo run run tests/ffi/benchmark/external_call`
Command: `cargo run --profile=release run tests/ffi/benchmark/external_call`
- Device1
- Device1-Linux-PVE
Lune release target: 0.205127 (sec)
Lune dev target: 1.556489 (sec)
> Commit: ddf0c4c
- Device2-Windows-11
Lune release target: 0.1875 (sec)
Lune dev target: ? SEGFUALT (sec)
> Commit: ddf0c4c
**LuaJit ffi**
Command: `luajit tests/ffi/benchmark/external_call/luajit.lua`
- Device1: 0.001682 (sec)
- Device1-Linux-PVE: 0.001682 (sec)
> LuaJIT 2.1.1727870382
> (flags = JIT ON SSE3 SSE4.1 BMI2 fold cse dce fwd dse narrow loop abc sink fuse)
**Deno ffi**
Command: `deno run --unstable-ffi --allow-ffi ./tests/ffi/benchmark/external_call/deno.ts`
- Device1: 0.006384 (sec)
- Device1-Linux-PVE: 0.006384 (sec)
> Deno 1.46.3 (v8 = 12.9.202.5-rusty)
**Sysinformation**
- Device1
- Device1-Linux-PVE
> CPU: AMD Ryzen 5 7600 (12) @ 5.1
> MEM: 61898MiB 5600 MT/s
> KERNEL: 6.8.12-2-pve (Proxmox VE 8.2.7 x86_64)
- Device2-Windows-11
> CPU: AMD Ryzen 5 7600 (4) @ 3.800GHz
> MEM: 12250MiB 5600 MT/s
> KERNEL: 10.0.22631 (Windows 11 x86_64)
> HOST: QEMU Standard PC (Q35 + ICH9, 2009)
28 changes: 20 additions & 8 deletions tests/ffi/utility/proc_clock/init.luau
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
-- FIXME: in windows, we need another library to get process cpu time

local ffi = require("@lune/ffi")
local process = require("@lune/process")
local is_windows = process.os == "windows"
local c = ffi.c

local proc_clock = {}
Expand All @@ -10,27 +14,35 @@ local lib = ffi.open(`{libdir}/lib.so`)

-- sizeof_clock
local sizeof_clock = c.fn({}, c.int):callable(lib:find("sizeof_clock"))
function proc_clock.sizeof_clock()
function proc_clock.sizeof_clock(): number
local result = ffi.box(c.int.size)
sizeof_clock(result)
return c.int:readData(result)
end

-- get_clock
local clock_t = ffi["u" .. (proc_clock.sizeof_clock() * 8)]
local clock_t = if is_windows then ffi.f32 else ffi["u" .. (proc_clock.sizeof_clock() * 8)]
assert(clock_t, "clock_t is unknown type")
local get_clock = c.fn({}, clock_t):callable(lib:find("get_clock"))
proc_clock.get_clock = get_clock
proc_clock.get_clock = (
if is_windows
then function(clock: ffi.BoxData | ffi.RefData)
ffi.f32:writeData(clock, os.clock())
end
else c.fn({}, clock_t):callable(lib:find("get_clock"))
) :: (ffi.BoxData | ffi.RefData) -> ()

-- get_offset
local get_offset = c.fn({ clock_t, clock_t }, ffi.f64):callable(lib:find("get_offset"))
function proc_clock.get_offset(before, after)
local get_offset: (ffi.BoxData, ffi.RefData, ffi.RefData) -> () = if is_windows
then function(result: ffi.BoxData, before: ffi.RefData, after: ffi.RefData)
ffi.f64:writeData(result, (ffi.f32:readData(after) - ffi.f32:readData(before)))
end
else c.fn({ clock_t, clock_t }, ffi.f64):callable(lib:find("get_offset"))
function proc_clock.get_offset(before: ffi.BoxData, after: ffi.BoxData): number
local result = ffi.box(ffi.f64.size)
get_offset(result, before:ref(), after:ref())
return ffi.f64:readData(result)
end

function proc_clock.new_box()
function proc_clock.new_box(): (ffi.BoxData, ffi.BoxData)
return ffi.box(clock_t.size), ffi.box(clock_t.size)
end

Expand Down

0 comments on commit b442ba7

Please sign in to comment.