forked from gnunicorn/ffi-gen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request gnunicorn#1 from bmcpt/shared_buffer
Shared buffer
- Loading branch information
Showing
22 changed files
with
1,374 additions
and
88 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
## build | ||
```sh | ||
cargo build --target wasm32-unknown-unknown && cp ../target/wasm32-unknown-unknown/debug/api.wasm js | ||
``` | ||
Added a new data type called 'buffer'. Example demonstrates how to use it. | ||
|
||
### run in node | ||
```sh | ||
node js/index.mjs | ||
``` | ||
|
||
### run in the browser | ||
```sh | ||
npx --yes http-server js | ||
``` | ||
cd example/dart | ||
cargo build | ||
LD_LIBRARY_PATH=../../target/debug dart bin/simple_bench.dart |
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,22 @@ | ||
/// Prints a friendly greeting to stdout. | ||
fn hello_world(); | ||
|
||
/// Returns a future that prints a friendly | ||
/// greeting to stdout. | ||
fn async_hello_world() -> Future<Result<u8>>; | ||
|
||
fn get_image() -> buffer<u8>; | ||
|
||
fn create(n: usize) -> DataTest; | ||
object DataTest { | ||
fn get_copy() -> Vec<u8>; | ||
fn get_shmem() -> buffer<u8>; | ||
} | ||
|
||
fn get_u8_counting(n: usize) -> buffer<u8>; | ||
fn get_u16_counting(n: usize) -> buffer<u16>; | ||
fn get_u32_counting(n: usize) -> buffer<u32>; | ||
fn get_u64_counting(n: usize) -> buffer<u64>; | ||
fn get_i8_counting(n: usize) -> buffer<i8>; | ||
fn get_i16_counting(n: usize) -> buffer<i16>; | ||
fn get_i32_counting(n: usize) -> buffer<i32>; | ||
fn get_i64_counting(n: usize) -> buffer<i64>; | ||
fn get_f32_counting(n: usize) -> buffer<f32>; | ||
fn get_f64_counting(n: usize) -> buffer<f64>; |
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,10 @@ | ||
import 'dart:io'; | ||
|
||
import '../lib/bindings.dart'; | ||
|
||
void main() async { | ||
final api = Api.load(); | ||
final img = await api.getImage(); | ||
print(img.toUint8List().length); | ||
File.fromUri(Uri.parse('t.jpg')).writeAsBytes(img.toUint8List()); | ||
} |
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
import '../lib/bindings.dart'; | ||
|
||
void main() async { | ||
final n = 1024 * 1024 * 10; | ||
|
||
final api = Api.load(); | ||
final data = api.create(n); | ||
final t1 = DateTime.now(); | ||
print(data.getCopy().length); | ||
final t2 = DateTime.now(); | ||
print(t2.difference(t1).inMilliseconds); | ||
print(data.getShmem().toUint8List().length); | ||
final t3 = DateTime.now(); | ||
print(t3.difference(t2).inMilliseconds); | ||
} |
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,33 @@ | ||
import '../lib/bindings.dart'; | ||
|
||
void main() async { | ||
final api = Api.load(); | ||
final u8s = api.getU8Counting(20).toUint8List(); | ||
final u16s = api.getU16Counting(20).toUint16List(); | ||
final u32s = api.getU32Counting(20).toUint32List(); | ||
final u64s = api.getU64Counting(20).toUint64List(); | ||
final i8s = api.getI8Counting(20).toInt8List(); | ||
final i16s = api.getI16Counting(20).toInt16List(); | ||
final i32s = api.getI32Counting(20).toInt32List(); | ||
final i64s = api.getI64Counting(20).toInt64List(); | ||
final f32s = api.getF32Counting(20).toFloat32List(); | ||
final f64s = api.getF64Counting(20).toFloat64List(); | ||
for (final i in positiveIntegers.take(20)) { | ||
assert(u8s[i] == i); | ||
assert(u16s[i] == i); | ||
assert(u32s[i] == i); | ||
assert(u64s[i] == i); | ||
assert(i8s[i] == i); | ||
assert(i16s[i] == i); | ||
assert(i32s[i] == i); | ||
assert(i64s[i] == i); | ||
assert(f32s[i] == i); | ||
assert(f64s[i] == i); | ||
} | ||
print('ok'); | ||
} | ||
|
||
Iterable<int> get positiveIntegers sync* { | ||
int i = 0; | ||
while (true) yield i++; | ||
} |
Oops, something went wrong.