Skip to content

Commit

Permalink
Move to mimalloc for rust. (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
tritoke authored Feb 6, 2021
1 parent 837846a commit 0ec24b4
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@
# csharp
/bin
/obj


# Added by cargo

/target
9 changes: 6 additions & 3 deletions build-rs.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env sh

mkdir -p build/rust
rustc -O -o build/rust/almost_pseudo_random src/main/rust/almost_pseudo_random.rs
rustc -O -o build/rust/rust_safer src/main/rust/rust_safer.rs
rustc -O -o build/rust/rust_raw src/main/rust/rust_raw.rs
cargo build --release --manifest-path src/main/rust/Cargo.toml
find src/main/rust/target/release \
-maxdepth 1 \
-executable \
-type f \
-exec cp -f {} build/rust \;
5 changes: 4 additions & 1 deletion src/main/c/almost_pseudo_random.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2021 Kazimierz Pogoda
* Copyright 2021 Sam Leonard
*
* This file is part of java-2-times-faster-than-c.
*
Expand All @@ -26,10 +27,12 @@ double almost_pseudo_random(long ordinal) {
return fmod(sin(((double) ordinal) * 100000.0) + 1.0, 1.0);
}

void main() {
int main() {
double checksum = 0;
for (long i = 0; i < ITERATION_COUNT; i++) {
checksum += almost_pseudo_random(i);
}
printf("checksum: %f\n", checksum);

return 0;
}
2 changes: 2 additions & 0 deletions src/main/rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target
Cargo.lock
11 changes: 11 additions & 0 deletions src/main/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "rust"
version = "0.1.0"
authors = ["Sam <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
# compile mimalloc for speed not security
mimalloc = { version = "~0.1.24", default-features = false }
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@

use std::ptr;

use mimalloc::MiMalloc;

#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;

const MAX_PAYLOAD_SIZE: i32 = 50;
const INITIAL_NODE_COUNT: i32 = 10000;
const MUTATION_COUNT: i64 = 1000000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@

use std::ptr;

use mimalloc::MiMalloc;

#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;

const MAX_PAYLOAD_SIZE: i32 = 50;
const INITIAL_NODE_COUNT: i32 = 10000;
const MUTATION_COUNT: i64 = 1000000;
Expand Down

0 comments on commit 0ec24b4

Please sign in to comment.