| Rust | C | C++ | |
|---|---|---|---|
| Initial buffer | file size or 1 MB | 16 KB | file size* |
| Buffer growth | 8 KB | doubling | n/a |
| Max read() | buffer size | 16 KB | 128 B |
| Work unit | 2 KB | entire sequence | 64 KB |
* the C++ code crashes if the input is not a file
| #include <stdio.h> | |
| void main() { | |
| int x = 5; | |
| int *p = &x; | |
| int *q = &*p; | |
| *q = 6; | |
| printf("%d\n", x); | |
| } |
| use std::{cmp, mem, ops, ptr, slice}; | |
| use std::marker::PhantomData; | |
| /// A growable vector the width of a single pointer. | |
| /// | |
| /// `PointerVec<T>` is similar to the standard `Vec<T>` type, but it stores its length and capacity | |
| /// fields in its heap allocation, rather than inline. This means that the `PointerVec` struct | |
| /// itself only has a single field, the pointer to the heap. | |
| pub struct PointerVec<T> { | |
| ptr: *mut Header, |
| Rust | C | C++ | |
|---|---|---|---|
| Initial buffer | file size or 1 MB | 16 KB | file size* |
| Buffer growth | 8 KB | doubling | n/a |
| Max read() | buffer size | 16 KB | 128 B |
| Work unit | 2 KB | entire sequence | 64 KB |
* the C++ code crashes if the input is not a file
| extern crate crypto; | |
| extern crate rand; | |
| use crypto::aes; | |
| use crypto::buffer::{ReadBuffer, WriteBuffer, RefReadBuffer, RefWriteBuffer, BufferResult}; | |
| use crypto::blockmodes::PkcsPadding; | |
| use rand::{Rng, OsRng}; | |
| use std::fs::File; | |
| use std::io; | |
| use std::io::prelude::*; |
| [package] | |
| name = "workspace" | |
| version = "0.1.0" | |
| authors = ["Matt Brubeck <mbrubeck@limpet.net>"] | |
| [lib] | |
| name = "workspace" | |
| crate-type = ["staticlib"] | |
| [dependencies] |
| #![feature(libc)] | |
| #![feature(test)] | |
| extern crate libc; | |
| extern crate test; | |
| extern crate seahash; | |
| use std::slice; | |
| use std::ffi::CStr; | |
| use std::panic; | |
| use std::str; |
| bench: libauthz.so | |
| python2 main.py | |
| libauthz.so: rusty_authz.rs Makefile | |
| rustc -C opt-level=3 -C lto rusty_authz.rs --crate-type cdylib -o libauthz.so | |
| .PHONY: bench |
| test environment | |
| rustc 1.16.0-nightly (5d994d8b7 2017-01-05) | |
| Thinkpad X1 Carbon Touch (2012) | |
| Intel(R) Core(TM) i7-3667U CPU @ 2.00GHz | |
| cpufreq-set -g performance | |
| no other programs running | |
| all results are after one run to warm up the cache | |
| regex | |
| opt-level = 3 |