Skip to content

Commit

Permalink
Add more diverse benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
EricLBuehler committed Jul 10, 2023
1 parent 32abbf5 commit cbd0c1d
Show file tree
Hide file tree
Showing 3 changed files with 257 additions and 25 deletions.
222 changes: 222 additions & 0 deletions BENCHMARKS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
# Benchmarks

Test platforms:
- WSL2 5.15.90 + Intel Xeon E3-1535M (x86_64)
- Ubuntu 20.04 + Intel Xeon Platinum 8358 (x86_64)
- Debian 6.1.20 + ARM Neoverse-N1 (aarch64)

## WSL2 5.15.90 + Intel Xeon E3-1535M (x86_64)

```shell
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
git clone https://github.com/EricLBuehler/trc.git
cd trc
# Benchmarks
cargo install cargo-criterion
cargo criterion
# Tests
rustup +nightly component add miri
cargo +nightly miri test
MIRIFLAGS="-Zmiri-strict-provenance" cargo +nightly miri test
MIRIFLAGS="-Zmiri-symbolic-alignment-check" cargo +nightly miri test
MIRIFLAGS="-Zmiri-tree-borrows" cargo +nightly miri test
```

<span style="color:green">**All tests passed**</span>.

### Clone
| Type | Mean time |
| --- | ----------- |
| Trc | 36.201ns |
| Arc | 43.793ns |
| Rc | 14.112ns |

### Multiple Clone (100 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 350.000ns |
| Arc | 1331.900ns |
| Rc | 303.73ns |

### Deref
| Type | Mean time |
| --- | ----------- |
| Trc | 26.978ns |
| Arc | 24.745ns |
| Rc | 12.249ns |

### Multiple Deref (100 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 55.148ns |
| Arc | 54.261ns |
| Rc | 44.764ns |

### Multiple Threads Drop and Clone (1000 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 10.945ms |
| Arc | 13.754ms |

### Multiple Threads Drop and Clone (5000 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 12.300ms |
| Arc | 18.104ms |

### Multiple Threads Drop and Clone (100000 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 30.666ms |
| Arc | 126.330ms |


## Ubuntu 20.04 + Intel Xeon Platinum 8358 (x86_64)

```shell
sudo apt update
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
git clone https://github.com/EricLBuehler/trc.git
cd trc
# Benchmarks
cargo install cargo-criterion
cargo criterion
# Tests
rustup +nightly component add miri
cargo +nightly miri test
MIRIFLAGS="-Zmiri-strict-provenance" cargo +nightly miri test
MIRIFLAGS="-Zmiri-symbolic-alignment-check" cargo +nightly miri test
MIRIFLAGS="-Zmiri-tree-borrows" cargo +nightly miri test
```

<span style="color:green">**All tests passed**</span>.

### Clone
| Type | Mean time |
| --- | ----------- |
| Trc | 26.913ns |
| Arc | 33.803ns |
| Rc | 11.228ns |

### Multiple Clone (100 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 423.020ns |
| Arc | 1273.200ns |
| Rc | 352.920ns |

### Deref
| Type | Mean time |
| --- | ----------- |
| Trc | 20.802ns |
| Arc | 20.802ns |
| Rc | 9.264ns |

### Multiple Deref (100 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 35.577ns |
| Arc | 35.853ns |
| Rc | 29.454ns |

### Multiple Threads Drop and Clone (1000 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 2.80ms |
| Arc | 4.02ms |

### Multiple Threads Drop and Clone (5000 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 3.480ms |
| Arc | 9.415ms |

### Multiple Threads Drop and Clone (100000 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 18.451ms |
| Arc | 137.980ms |

### Multiple Threads Drop and Clone (500000 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 71.490ms |
| Arc | 638.180ms |


## Debian 6.1.20 + ARM Neoverse-N1 (aarch64)

```shell
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
git clone https://github.com/EricLBuehler/trc.git
cd trc
sudo apt install git
sudo apt install build-essential
# Benchmarks
cargo install cargo-criterion
cargo criterion
# Tests
rustup +nightly component add miri
cargo +nightly miri test
MIRIFLAGS="-Zmiri-strict-provenance" cargo +nightly miri test
MIRIFLAGS="-Zmiri-symbolic-alignment-check" cargo +nightly miri test
MIRIFLAGS="-Zmiri-tree-borrows" cargo +nightly miri test
```

<span style="color:green">**All tests passed**</span>.


### Clone
| Type | Mean time |
| --- | ----------- |
| Trc | 45.005ns |
| Arc | 42.873ns |
| Rc | 16.684ns |

### Multiple Clone (100 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 422.680ns |
| Arc | 1208.100ns |
| Rc | 353.41ns |

### Deref
| Type | Mean time |
| --- | ----------- |
| Trc | 28.721ns |
| Arc | 32.815ns |
| Rc | 14.134ns |

### Multiple Deref (100 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 62.983ns |
| Arc | 61.937ns |
| Rc | 48.643ns |

### Multiple Threads Drop and Clone (1000 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 1.883ms |
| Arc | 2.913ms |

### Multiple Threads Drop and Clone (5000 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 2.424ms |
| Arc | 7.672ms |

### Multiple Threads Drop and Clone (100000 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 16.535ms |
| Arc | 119.950ms |

### Multiple Threads Drop and Clone (500000 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 71.543ms |
| Arc | 590.530ms |
52 changes: 27 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,65 +86,67 @@ Benchmarks via Criterion. As can be seen, `Trc`'s performance realy shines when
The reason `Trc` does not do as well for fewer operations is because it needs to allocate `n+1` blocks of memory for `n` threads, and
so for 1 thread, there are 2 allocations. However, after the initial allocations, `Trc` performs very well - 3.81x `Arc`'s time for Clones.

### Clone
Click [here](BENCHMARKS.md) for more benchmarks. Multiple different operating systems, CPUs, and architectures are tested.

### Clone
| Type | Mean time |
| --- | ----------- |
| Trc | 36.201ms |
| Arc | 43.793ns |
| Rc | 14.112ns |
| Trc | 26.913ns |
| Arc | 33.803ns |
| Rc | 11.228ns |

### Multiple Clone (100 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 350.000ns |
| Arc | 1331.900ns |
| Rc | 303.73ns |
| Trc | 423.020ns |
| Arc | 1273.200ns |
| Rc | 352.920ns |

### Deref
| Type | Mean time |
| --- | ----------- |
| Trc | 26.978ns |
| Arc | 24.745ns |
| Rc | 12.249ns |
| Trc | 20.802ns |
| Arc | 20.802ns |
| Rc | 9.264ns |

### Multiple Deref (100 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 55.148ns |
| Arc | 54.261ns |
| Rc | 44.764ns |
| Trc | 35.577ns |
| Arc | 35.853ns |
| Rc | 29.454ns |

### Multiple Threads Drop and Clone (1000 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 10.945ms |
| Arc | 13.754ms |
| Trc | 2.80ms |
| Arc | 4.02ms |

1.26x faster - because of the allocation cost of `SharedTrc`.
1.44x faster - because of the allocation cost of `SharedTrc`.

### Multiple Threads Drop and Clone (5000 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 12.300ms |
| Arc | 18.104ms |
| Trc | 3.480ms |
| Arc | 9.415ms |

1.47x faster - the allocation cost of `SharedTrc` begins to become replaced by the `Clone` effiency.
2.71x faster - the allocation cost of `SharedTrc` begins to become replaced by the `Clone` effiency.

### Multiple Threads Drop and Clone (100000 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 30.666ms |
| Arc | 126.330ms |
| Trc | 18.451ms |
| Arc | 137.980ms |

4.12x faster - the allocation cost of `SharedTrc` is now negligible and the `Clone` advantage is beginning to be demonstrated.
7.44x faster - the allocation cost of `SharedTrc` is now negligible and the `Clone` advantage is beginning to be demonstrated.

### Multiple Threads Drop and Clone (500000 times)
| Type | Mean time |
| --- | ----------- |
| Trc | 88.387ms |
| Arc | 534.670ms |
| Trc | 71.490ms |
| Arc | 638.180ms |

6.05x faster - the allocation cost of `SharedTrc` is now negligible and the `Clone` advantage is demonstrated.
8.92x faster - the allocation cost of `SharedTrc` is now negligible and the `Clone` advantage is demonstrated.

![Trc vs Arc performance](./figures/performance.png)

Expand Down
8 changes: 8 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,11 @@ fn readme_multi_weak() {
handle.join().unwrap();
assert_eq!(*trc, 100);
}

#[test]
fn test_rc_issue_uninit() {
//https://github.com/rust-lang/rust/issues/95334
//Cannot use isize::MAX on my 64-bit system
let p = Trc::<[u8]>::new_uninit_slice(2_usize.pow(16));
let _ = p.last();
}

0 comments on commit cbd0c1d

Please sign in to comment.