summaryrefslogtreecommitdiff
path: root/test_ffi/tests
diff options
context:
space:
mode:
Diffstat (limited to 'test_ffi/tests')
-rw-r--r--test_ffi/tests/bench.js51
-rw-r--r--test_ffi/tests/test.js15
2 files changed, 46 insertions, 20 deletions
diff --git a/test_ffi/tests/bench.js b/test_ffi/tests/bench.js
index da29f482f..084615575 100644
--- a/test_ffi/tests/bench.js
+++ b/test_ffi/tests/bench.js
@@ -12,6 +12,8 @@ const libPath = `${targetDir}/${libPrefix}test_ffi.${libSuffix}`;
const dylib = Deno.dlopen(libPath, {
"nop": { parameters: [], result: "void" },
"add_u32": { parameters: ["u32", "u32"], result: "u32" },
+ "add_u64": { parameters: ["u64", "u64"], result: "u64" },
+ "ffi_string": { parameters: [], result: "pointer" },
"hash": { parameters: ["pointer", "u32"], result: "u32" },
"nop_u8": { parameters: ["u8"], result: "void" },
"nop_i8": { parameters: ["i8"], result: "void" },
@@ -227,16 +229,42 @@ Deno.bench("nop()", () => {
nop();
});
+const bytes = new Uint8Array(64);
+
+const { hash } = dylib.symbols;
+Deno.bench("hash()", () => {
+ hash(bytes, bytes.byteLength);
+});
+
+const { ffi_string } = dylib.symbols;
+Deno.bench(
+ "c string",
+ () => new Deno.UnsafePointerView(ffi_string()).getCString(),
+);
+
const { add_u32 } = dylib.symbols;
Deno.bench("add_u32()", () => {
add_u32(1, 2);
});
-const bytes = new Uint8Array(64);
+const { return_buffer } = dylib.symbols;
+Deno.bench("return_buffer()", () => {
+ return_buffer();
+});
-const { hash } = dylib.symbols;
-Deno.bench("hash()", () => {
- hash(bytes, bytes.byteLength);
+const { add_u64 } = dylib.symbols;
+Deno.bench("add_u64()", () => {
+ add_u64(1, 2);
+});
+
+const { return_u64 } = dylib.symbols;
+Deno.bench("return_u64()", () => {
+ return_u64();
+});
+
+const { return_i64 } = dylib.symbols;
+Deno.bench("return_i64()", () => {
+ return_i64();
});
const { nop_u8 } = dylib.symbols;
@@ -348,16 +376,6 @@ Deno.bench("return_i32()", () => {
return_i32();
});
-const { return_u64 } = dylib.symbols;
-Deno.bench("return_u64()", () => {
- return_u64();
-});
-
-const { return_i64 } = dylib.symbols;
-Deno.bench("return_i64()", () => {
- return_i64();
-});
-
const { return_usize } = dylib.symbols;
Deno.bench("return_usize()", () => {
return_usize();
@@ -378,11 +396,6 @@ Deno.bench("return_f64()", () => {
return_f64();
});
-const { return_buffer } = dylib.symbols;
-Deno.bench("return_buffer()", () => {
- return_buffer();
-});
-
// Nonblocking calls
const { nop_nonblocking } = dylib.symbols;
diff --git a/test_ffi/tests/test.js b/test_ffi/tests/test.js
index e27a09d4f..d658ec169 100644
--- a/test_ffi/tests/test.js
+++ b/test_ffi/tests/test.js
@@ -197,7 +197,20 @@ dylib.symbols.print_buffer(buffer, buffer.length);
const subarray = buffer.subarray(3);
dylib.symbols.print_buffer(subarray, subarray.length - 2);
dylib.symbols.print_buffer2(buffer, buffer.length, buffer2, buffer2.length);
-const ptr0 = dylib.symbols.return_buffer();
+
+const { return_buffer } = symbols;
+function returnBuffer() { return return_buffer(); };
+
+%PrepareFunctionForOptimization(returnBuffer);
+returnBuffer();
+%OptimizeFunctionOnNextCall(returnBuffer);
+const ptr0 = returnBuffer();
+
+const status = %GetOptimizationStatus(returnBuffer);
+if (!(status & (1 << 4))) {
+ throw new Error("returnBuffer is not optimized");
+}
+
dylib.symbols.print_buffer(ptr0, 8);
const ptrView = new Deno.UnsafePointerView(ptr0);
const into = new Uint8Array(6);