Add Space Lua benchmarks based on Deno.bench aligned to Deno.test (#1649)

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
This commit is contained in:
Matouš Jan Fialka
2025-11-05 15:06:33 +01:00
committed by GitHub
parent df28a3f04d
commit 3422a9fa20
4 changed files with 102 additions and 4 deletions
+5
View File
@@ -30,6 +30,11 @@ test:
# Run backend tests
go test ./server/...
.PHONY: bench
bench:
# Run frontend tests
deno task bench
generate:
# Regenerate the Lua parser from the the grammar
deno run -A npm:@lezer/generator@1.5.1 client/space_lua/lua.grammar -o client/space_lua/parse-lua.js
+91
View File
@@ -0,0 +1,91 @@
import { parse } from "../client/space_lua/parse.ts";
import { luaBuildStandardEnv } from "../client/space_lua/stdlib.ts";
import {
LuaEnv,
LuaRuntimeError,
LuaStackFrame,
} from "../client/space_lua/runtime.ts";
import { evalStatement } from "../client/space_lua/eval.ts";
import { assert } from "@std/assert/assert";
import { fileURLToPath } from "node:url";
Deno.bench("[Lua] Core language", async () => {
await runLuaTest("../client/space_lua/language_core_test.lua");
});
Deno.bench("[Lua] Core language (length)", async () => {
await runLuaTest("../client/space_lua/len_test.lua");
});
Deno.bench("[Lua] Core language (truthiness)", async () => {
await runLuaTest("../client/space_lua/truthiness_test.lua");
});
Deno.bench("[Lua] Core language (arithmetic)", async () => {
await runLuaTest("../client/space_lua/arithmetic_test.lua");
});
Deno.bench("[Lua] Load tests", async () => {
await runLuaTest("../client/space_lua/stdlib/load_test.lua");
});
Deno.bench("[Lua] Table tests", async () => {
await runLuaTest("../client/space_lua/stdlib/table_test.lua");
});
Deno.bench("[Lua] String to number tests", async () => {
await runLuaTest("../client/space_lua/tonumber_test.lua");
});
Deno.bench("[Lua] String tests", async () => {
await runLuaTest("../client/space_lua/stdlib/string_test.lua");
// await runLuaTest("../client/space_lua/stdlib/string_test2.lua");
});
Deno.bench("[Lua] Space Lua tests", async () => {
await runLuaTest("../client/space_lua/stdlib/space_lua_test.lua");
});
Deno.bench("[Lua] OS tests", async () => {
await runLuaTest("../client/space_lua/stdlib/os_test.lua");
});
Deno.bench("[Lua] Math tests", async () => {
await runLuaTest("../client/space_lua/stdlib/math_test.lua");
});
Deno.bench("[Lua] JS tests", async () => {
await runLuaTest("../client/space_lua/stdlib/js_test.lua");
});
Deno.bench("[Lua] Global functions tests", async () => {
await runLuaTest("../client/space_lua/stdlib/global_test.lua");
});
Deno.bench("[Lua] Encoding functions tests", async () => {
await runLuaTest("../client/space_lua/stdlib/encoding_test.lua");
});
Deno.bench("[Lua] Lume functions tests", async () => {
await runLuaTest("../client/space_lua/lume_test.lua");
});
async function runLuaTest(luaPath: string) {
const luaFile = await Deno.readTextFile(
fileURLToPath(new URL(luaPath, import.meta.url)),
);
const chunk = parse(luaFile, {});
const env = new LuaEnv(luaBuildStandardEnv());
const sf = LuaStackFrame.createWithGlobalEnv(env, chunk.ctx);
try {
await evalStatement(chunk, env, sf);
} catch (e: any) {
if (e instanceof LuaRuntimeError) {
console.error(`Error evaluating script:`, e.toPrettyString(luaFile));
} else {
console.error(`Error evaluating script:`, e);
}
assert(false);
}
}
+5 -4
View File
@@ -215,21 +215,22 @@ assert(t.bar == "bar")
assertEqual(t.foo, "Key not found: foo")
-- Test the __newindex metamethod
t = setmetatable(
t, c = setmetatable(
{}, {
__newindex = function(table, key, value)
print("Raw set", key, value)
c = c + 1
rawset(table, key, "Value: " .. value)
print("Raw set done")
c = c + 1
end
}
)
), 0
t.name = "John"
-- rawset ignores the metamethod
rawset(t, "age", 100)
assertEqual(t.name, "Value: John")
assertEqual(t.age, 100)
assertEqual(c, 2)
-- Test some of the operator metamethods
t = setmetatable(
+1
View File
@@ -10,6 +10,7 @@
"lint": "deno lint --fix",
"fmt": "deno fmt",
"test": "deno test -A",
"bench": "deno bench -A",
"plugs": "deno run -A build_plugs_libraries.ts"
},
"publish": {