summaryrefslogtreecommitdiff
path: root/test_ffi
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2022-07-28 18:08:22 +0530
committerGitHub <noreply@github.com>2022-07-28 18:08:22 +0530
commitef7bc2e6cc4856a0372086b3ceb7d470508aaa52 (patch)
tree02045406d0fe21bf77bcb3697ed2e75006aebeed /test_ffi
parent519ed44ebb4bab71c6b80f7c1ef432354654da8c (diff)
perf(ext/ffi): use fast api calls for 64bit return types (#15313)
Diffstat (limited to 'test_ffi')
-rw-r--r--test_ffi/src/lib.rs7
-rw-r--r--test_ffi/tests/bench.js51
-rw-r--r--test_ffi/tests/test.js15
3 files changed, 53 insertions, 20 deletions
diff --git a/test_ffi/src/lib.rs b/test_ffi/src/lib.rs
index bc89bd66c..b061ca8d5 100644
--- a/test_ffi/src/lib.rs
+++ b/test_ffi/src/lib.rs
@@ -404,3 +404,10 @@ pub struct Structure {
#[no_mangle]
pub static mut static_ptr: Structure = Structure { _data: 42 };
+
+static STRING: &str = "Hello, world!\0";
+
+#[no_mangle]
+extern "C" fn ffi_string() -> *const u8 {
+ STRING.as_ptr()
+}
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);