| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent be1b204 commit f52cf5e
50 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,28 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common.js'); | ||
| 4 | + const ffi = require('node:ffi'); | ||
| 5 | + const { libraryPath, ensureFixtureLibrary } = require('./common.js'); | ||
| 6 | + | ||
| 7 | + const bench = common.createBenchmark(main, { | ||
| 8 | + n: [1e7], | ||
| 9 | + }, { | ||
| 10 | + flags: ['--experimental-ffi'], | ||
| 11 | + }); | ||
| 12 | + | ||
| 13 | + ensureFixtureLibrary(); | ||
| 14 | + | ||
| 15 | + const { lib, functions } = ffi.dlopen(libraryPath, { | ||
| 16 | + add_f64: { return: 'f64', arguments: ['f64', 'f64'] }, | ||
| 17 | + }); | ||
| 18 | + | ||
| 19 | + const add = functions.add_f64; | ||
| 20 | + | ||
| 21 | + function main({ n }) { | ||
| 22 | + bench.start(); | ||
| 23 | + for (let i = 0; i < n; ++i) | ||
| 24 | + add(20.5, 21.5); | ||
| 25 | + bench.end(n); | ||
| 26 | + | ||
| 27 | + lib.close(); | ||
| 28 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,28 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common.js'); | ||
| 4 | + const ffi = require('node:ffi'); | ||
| 5 | + const { libraryPath, ensureFixtureLibrary } = require('./common.js'); | ||
| 6 | + | ||
| 7 | + const bench = common.createBenchmark(main, { | ||
| 8 | + n: [1e7], | ||
| 9 | + }, { | ||
| 10 | + flags: ['--experimental-ffi'], | ||
| 11 | + }); | ||
| 12 | + | ||
| 13 | + ensureFixtureLibrary(); | ||
| 14 | + | ||
| 15 | + const { lib, functions } = ffi.dlopen(libraryPath, { | ||
| 16 | + add_f32: { return: 'f32', arguments: ['f32', 'f32'] }, | ||
| 17 | + }); | ||
| 18 | + | ||
| 19 | + const add = functions.add_f32; | ||
| 20 | + | ||
| 21 | + function main({ n }) { | ||
| 22 | + bench.start(); | ||
| 23 | + for (let i = 0; i < n; ++i) | ||
| 24 | + add(20.5, 21.5); | ||
| 25 | + bench.end(n); | ||
| 26 | + | ||
| 27 | + lib.close(); | ||
| 28 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,28 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common.js'); | ||
| 4 | + const ffi = require('node:ffi'); | ||
| 5 | + const { libraryPath, ensureFixtureLibrary } = require('./common.js'); | ||
| 6 | + | ||
| 7 | + const bench = common.createBenchmark(main, { | ||
| 8 | + n: [1e7], | ||
| 9 | + }, { | ||
| 10 | + flags: ['--experimental-ffi'], | ||
| 11 | + }); | ||
| 12 | + | ||
| 13 | + ensureFixtureLibrary(); | ||
| 14 | + | ||
| 15 | + const { lib, functions } = ffi.dlopen(libraryPath, { | ||
| 16 | + add_i16: { return: 'i16', arguments: ['i16', 'i16'] }, | ||
| 17 | + }); | ||
| 18 | + | ||
| 19 | + const add = functions.add_i16; | ||
| 20 | + | ||
| 21 | + function main({ n }) { | ||
| 22 | + bench.start(); | ||
| 23 | + for (let i = 0; i < n; ++i) | ||
| 24 | + add(20, 22); | ||
| 25 | + bench.end(n); | ||
| 26 | + | ||
| 27 | + lib.close(); | ||
| 28 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,28 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common.js'); | ||
| 4 | + const ffi = require('node:ffi'); | ||
| 5 | + const { libraryPath, ensureFixtureLibrary } = require('./common.js'); | ||
| 6 | + | ||
| 7 | + const bench = common.createBenchmark(main, { | ||
| 8 | + n: [1e7], | ||
| 9 | + }, { | ||
| 10 | + flags: ['--experimental-ffi'], | ||
| 11 | + }); | ||
| 12 | + | ||
| 13 | + ensureFixtureLibrary(); | ||
| 14 | + | ||
| 15 | + const { lib, functions } = ffi.dlopen(libraryPath, { | ||
| 16 | + add_i64: { return: 'i64', arguments: ['i64', 'i64'] }, | ||
| 17 | + }); | ||
| 18 | + | ||
| 19 | + const add = functions.add_i64; | ||
| 20 | + | ||
| 21 | + function main({ n }) { | ||
| 22 | + bench.start(); | ||
| 23 | + for (let i = 0; i < n; ++i) | ||
| 24 | + add(20n, 22n); | ||
| 25 | + bench.end(n); | ||
| 26 | + | ||
| 27 | + lib.close(); | ||
| 28 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,28 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common.js'); | ||
| 4 | + const ffi = require('node:ffi'); | ||
| 5 | + const { libraryPath, ensureFixtureLibrary } = require('./common.js'); | ||
| 6 | + | ||
| 7 | + const bench = common.createBenchmark(main, { | ||
| 8 | + n: [1e7], | ||
| 9 | + }, { | ||
| 10 | + flags: ['--experimental-ffi'], | ||
| 11 | + }); | ||
| 12 | + | ||
| 13 | + ensureFixtureLibrary(); | ||
| 14 | + | ||
| 15 | + const { lib, functions } = ffi.dlopen(libraryPath, { | ||
| 16 | + add_i8: { return: 'i8', arguments: ['i8', 'i8'] }, | ||
| 17 | + }); | ||
| 18 | + | ||
| 19 | + const add = functions.add_i8; | ||
| 20 | + | ||
| 21 | + function main({ n }) { | ||
| 22 | + bench.start(); | ||
| 23 | + for (let i = 0; i < n; ++i) | ||
| 24 | + add(20, 22); | ||
| 25 | + bench.end(n); | ||
| 26 | + | ||
| 27 | + lib.close(); | ||
| 28 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,28 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common.js'); | ||
| 4 | + const ffi = require('node:ffi'); | ||
| 5 | + const { libraryPath, ensureFixtureLibrary } = require('./common.js'); | ||
| 6 | + | ||
| 7 | + const bench = common.createBenchmark(main, { | ||
| 8 | + n: [1e7], | ||
| 9 | + }, { | ||
| 10 | + flags: ['--experimental-ffi'], | ||
| 11 | + }); | ||
| 12 | + | ||
| 13 | + ensureFixtureLibrary(); | ||
| 14 | + | ||
| 15 | + const { lib, functions } = ffi.dlopen(libraryPath, { | ||
| 16 | + add_u16: { return: 'u16', arguments: ['u16', 'u16'] }, | ||
| 17 | + }); | ||
| 18 | + | ||
| 19 | + const add = functions.add_u16; | ||
| 20 | + | ||
| 21 | + function main({ n }) { | ||
| 22 | + bench.start(); | ||
| 23 | + for (let i = 0; i < n; ++i) | ||
| 24 | + add(20, 22); | ||
| 25 | + bench.end(n); | ||
| 26 | + | ||
| 27 | + lib.close(); | ||
| 28 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,28 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common.js'); | ||
| 4 | + const ffi = require('node:ffi'); | ||
| 5 | + const { libraryPath, ensureFixtureLibrary } = require('./common.js'); | ||
| 6 | + | ||
| 7 | + const bench = common.createBenchmark(main, { | ||
| 8 | + n: [1e7], | ||
| 9 | + }, { | ||
| 10 | + flags: ['--experimental-ffi'], | ||
| 11 | + }); | ||
| 12 | + | ||
| 13 | + ensureFixtureLibrary(); | ||
| 14 | + | ||
| 15 | + const { lib, functions } = ffi.dlopen(libraryPath, { | ||
| 16 | + add_u64: { return: 'u64', arguments: ['u64', 'u64'] }, | ||
| 17 | + }); | ||
| 18 | + | ||
| 19 | + const add = functions.add_u64; | ||
| 20 | + | ||
| 21 | + function main({ n }) { | ||
| 22 | + bench.start(); | ||
| 23 | + for (let i = 0; i < n; ++i) | ||
| 24 | + add(20n, 22n); | ||
| 25 | + bench.end(n); | ||
| 26 | + | ||
| 27 | + lib.close(); | ||
| 28 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,28 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common.js'); | ||
| 4 | + const ffi = require('node:ffi'); | ||
| 5 | + const { libraryPath, ensureFixtureLibrary } = require('./common.js'); | ||
| 6 | + | ||
| 7 | + const bench = common.createBenchmark(main, { | ||
| 8 | + n: [1e7], | ||
| 9 | + }, { | ||
| 10 | + flags: ['--experimental-ffi'], | ||
| 11 | + }); | ||
| 12 | + | ||
| 13 | + ensureFixtureLibrary(); | ||
| 14 | + | ||
| 15 | + const { lib, functions } = ffi.dlopen(libraryPath, { | ||
| 16 | + add_u8: { return: 'u8', arguments: ['u8', 'u8'] }, | ||
| 17 | + }); | ||
| 18 | + | ||
| 19 | + const add = functions.add_u8; | ||
| 20 | + | ||
| 21 | + function main({ n }) { | ||
| 22 | + bench.start(); | ||
| 23 | + for (let i = 0; i < n; ++i) | ||
| 24 | + add(20, 22); | ||
| 25 | + bench.end(n); | ||
| 26 | + | ||
| 27 | + lib.close(); | ||
| 28 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,30 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common.js'); | ||
| 4 | + const ffi = require('node:ffi'); | ||
| 5 | + const { libraryPath, ensureFixtureLibrary } = require('./common.js'); | ||
| 6 | + | ||
| 7 | + const bench = common.createBenchmark(main, { | ||
| 8 | + n: [1e7], | ||
| 9 | + }, { | ||
| 10 | + flags: ['--experimental-ffi'], | ||
| 11 | + }); | ||
| 12 | + | ||
| 13 | + ensureFixtureLibrary(); | ||
| 14 | + | ||
| 15 | + const { lib, functions } = ffi.dlopen(libraryPath, { | ||
| 16 | + first_byte: { return: 'u8', arguments: ['pointer'] }, | ||
| 17 | + }); | ||
| 18 | + | ||
| 19 | + const fn = functions.first_byte; | ||
| 20 | + const bytes = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]); | ||
| 21 | + const pointer = ffi.getRawPointer(bytes); | ||
| 22 | + | ||
| 23 | + function main({ n }) { | ||
| 24 | + bench.start(); | ||
| 25 | + for (let i = 0; i < n; ++i) | ||
| 26 | + fn(pointer); | ||
| 27 | + bench.end(n); | ||
| 28 | + | ||
| 29 | + lib.close(); | ||
| 30 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,29 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common.js'); | ||
| 4 | + const ffi = require('node:ffi'); | ||
| 5 | + const { libraryPath, ensureFixtureLibrary } = require('./common.js'); | ||
| 6 | + | ||
| 7 | + const bench = common.createBenchmark(main, { | ||
| 8 | + n: [1e7], | ||
| 9 | + }, { | ||
| 10 | + flags: ['--experimental-ffi'], | ||
| 11 | + }); | ||
| 12 | + | ||
| 13 | + ensureFixtureLibrary(); | ||
| 14 | + | ||
| 15 | + const { lib, functions } = ffi.dlopen(libraryPath, { | ||
| 16 | + first_byte: { return: 'u8', arguments: ['buffer'] }, | ||
| 17 | + }); | ||
| 18 | + | ||
| 19 | + const fn = functions.first_byte; | ||
| 20 | + const bytes = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]); | ||
| 21 | + | ||
| 22 | + function main({ n }) { | ||
| 23 | + bench.start(); | ||
| 24 | + for (let i = 0; i < n; ++i) | ||
| 25 | + fn(bytes); | ||
| 26 | + bench.end(n); | ||
| 27 | + | ||
| 28 | + lib.close(); | ||
| 29 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments