Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add benchmark for Koto #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
183 changes: 183 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mlua_lua54 = ["mlua/lua54", "mlua/vendored"]
mlua_luau = ["mlua/luau-jit"]
rhai = ["dep:rhai", "dep:itertools", "dep:anyhow"]
rune = ["dep:rune", "dep:anyhow"]
koto = ["dep:koto", "koto/rc"]

[dependencies]
rand = "0.8"
Expand All @@ -25,6 +26,7 @@ mlua = { version = "0.9.6", optional = true }
rhai = { version = "1.17.1", optional = true }
rquickjs = { version = "0.5.1", optional = true }
rune = { version = "0.13.2", optional = true }
koto = { version = "0.14.0", default-features = false, optional = true }

[dev-dependencies]
criterion = { version = "0.5" }
Expand Down Expand Up @@ -61,3 +63,8 @@ required-features = ["rquickjs"]
name = "rune"
harness = false
required-features = ["rune"]

[[bench]]
name = "koto"
harness = false
required-features = ["koto"]
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The project goal is to benchmark most popular embedded scripting languages for R
- [rhai](https://crates.io/crates/rhai)
- [rquickjs](https://crates.io/crates/rquickjs)
- [rune](https://crates.io/crates/rune)
- [koto](https://crates.io/crates/koto)

The benchmark is designed to cover not only the performance of code evaluation but interoperability with Rust too.

Expand All @@ -18,13 +19,14 @@ Simply run the `bench.py` script to generate images. It requires `cargo criterio

| | |
|----------|-------------------------------|
| OS | Ubuntu 23.04, r6i.8xlarge |
| OS | Pop!_OS 22.04 x86_64 |
| boa | v0.18.0 |
| mlua | v0.9.6 |
| rhai | v1.17.1 |
| rquickjs | v0.5.1 |
| rune | v0.13.2 |
| rustc | v1.76.0 |
| koto | v0.14.0 |
| rustc | v1.78.0 |

## Results

Expand Down
Binary file modified Sort Rust objects.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions benches/koto.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use criterion::{criterion_group, criterion_main, Criterion};

fn benchmark(c: &mut Criterion) {
script_bench::koto::sort_userdata(|func| {
c.bench_function("Sort Rust objects", |b| {
b.iter(|| func());
});
})
.unwrap();
}

criterion_group! {
name = benches;
config = Criterion::default().sample_size(10);
targets = benchmark,
}

criterion_main!(benches);
31 changes: 31 additions & 0 deletions scripts/sort_userdata.koto
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
charset = [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" ]

generate_string = |len|
data = []
for i in 0..len
data.push charset[rand(charset.count())]
data.fold "", |acc, el| '{acc}{el}'

partition = |arr, lo, hi|
pivot_idx = ((lo + hi) / 2).floor()
pivot = arr[pivot_idx]
j = lo
for i in lo..hi
if arr[i] < pivot
arr[i], arr[j] = arr[j], arr[i]
j += 1
arr[j], arr[hi] = arr[hi], arr[j]
j

quicksort = |arr, lo, hi|
while lo < hi
p = partition arr, lo, hi
quicksort arr, lo, (p - 1)
lo = p + 1


array = []
for _ in 0..10000
data = generate_string(8 + rand(16)) >> RustData_new
array.push data
quicksort array, 0, (array.count() - 1)
Loading