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
// Check if type T is a packed struct at comptime. | |
comptime { | |
assert(@typeInfo(T) == .Struct); | |
assert(@typeInfo(T).Struct.backing_integer != null); | |
} |
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
The solution to this problem with siphash was to reinitialize it every time you create a new hashmap. Specifically: when you create a HashMap you have to give it something that implements BuildHasher. The default way to do this is call RandomState::new, which pulls some randomness and stores it. Then whenever you go to hash something you call build_hasher on that which initializes a SipHasher13 using the state stored in the RandomState, which is different between hashmaps but always the same for the same hashmap. FxHashMap uses the other provided way to do this: BuildHasherDefault<H> implements BuildHasher as long as H implements Hasher + Default. | |
But we could be doing the same thing for FxHasher we do for SipHasher13, just initializing them to a value that's randomly chosen on HashMap creation. That solves the reinsertion performance problem without any impact on hashing performance. There's just currently no simple way to get that functionality into something that implements BuildHasher if all you have is |
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
sudo kill -9 `ps -A | grep -Fa 'sbin/coreaudiod' | head -n 1 | awk '{print $1}'` |
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
const MY_ARRAY = ['a', 'b', 'c'] as const | |
const objectWithKeysFromConstArrayElements: Record< | |
typeof MY_ARRAY[number], | |
string | |
> = { a: 'foo', b: 'bar', c: 'foobar' } |
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
#!/usr/bin/env bash | |
# Clone the repository | |
REMOTE_URL="$(git config --get remote.origin.url)"; | |
cd ${TRAVIS_BUILD_DIR}/.. && \ | |
git clone ${REMOTE_URL} "${TRAVIS_REPO_SLUG}-bench" && \ | |
cd "${TRAVIS_REPO_SLUG}-bench" && \ | |
# Bench master | |
git checkout master && \ |
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
language: rust | |
rust: | |
- stable | |
- beta | |
- nightly | |
matrix: | |
allow_failures: | |
- rust: nightly |
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
use criterion::{criterion_group, criterion_main, Criterion}; | |
fn minus_one_benchmark(c: &mut Criterion) { | |
c.bench_function("Bench the minus one function", |b| b.iter(|| minus_one(1))); | |
} | |
criterion_group!(benches, minus_one_benchmark); | |
criterion_main!(benches); |
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
[dev-dependencies] | |
criterion = "0.2" | |
[[bench]] | |
name = "benchmark" | |
harness = false |
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
#![feature(test)] | |
extern crate test; | |
pub fn minus_one(number: i32) -> i32 { | |
number - 1 | |
} | |
#[cfg(test)] | |
mod tests { |
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
pub fn minus_one(number: i32) -> i32 { | |
number - 1 | |
} | |
#[cfg(test)] | |
mod tests { | |
use super::*; | |
#[test] | |
fn test_minus_one() { | |
assert_eq!(minus_one(1), 0); |
NewerOlder