-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
112 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as Comlink from 'comlink'; | ||
|
||
const TestSum: any = Comlink.wrap( | ||
// @ts-ignore | ||
new Worker(new URL('./worker.ts', import.meta.url)), | ||
); | ||
|
||
(async function () { | ||
const inst = await new TestSum(); | ||
console.log(await inst.test()); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as Comlink from 'comlink'; | ||
|
||
import init, { sum, initThreadPool } from '../../wasm/basic-rayon/pkg'; | ||
|
||
class TestSum { | ||
async test() { | ||
console.log('init'); | ||
await init(); | ||
console.log('initThreadPool'); | ||
// @ts-ignore | ||
await initThreadPool(navigator.hardwareConcurrency * 2); | ||
console.log('sum'); | ||
const arr = Int32Array.from({ length: 100 }, (_, i) => i + 1); | ||
return sum(arr); | ||
} | ||
} | ||
|
||
Comlink.expose(TestSum); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import * as Comlink from 'comlink'; | ||
import TLSN from './tlsn'; | ||
|
||
export default TLSN; | ||
// export default TLSN; | ||
|
||
Comlink.expose(TLSN); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
authors = ["The tlsn-extension Developers"] | ||
description = "tlsn-js library for using TLSNotary in browsers" | ||
edition = "2018" | ||
license = "MIT OR Apache-2.0" | ||
name = "tlsn-extension-rs" | ||
rust-version = "1.56" | ||
version = "0.1.0" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[dependencies] | ||
wasm-bindgen = "0.2" | ||
rayon = "1.8" | ||
wasm-bindgen-rayon = "1.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
pub use wasm_bindgen_rayon::init_thread_pool; | ||
|
||
use wasm_bindgen::prelude::wasm_bindgen; | ||
|
||
use rayon::iter::IntoParallelRefIterator; | ||
use rayon::iter::ParallelIterator; | ||
|
||
|
||
|
||
#[wasm_bindgen] | ||
pub fn sum(numbers: &[i32]) -> i32 { | ||
numbers.par_iter().sum() | ||
} |