Skip to content

Instantly share code, notes, and snippets.

@mbrubeck
mbrubeck / rust-opt-level-measurements.txt
Last active May 2, 2022 22:35
Rust opt-level measurements
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
#![allow(dead_code)]
use chrono::prelude::*;
use chrono::Duration;
use redux_rs::{Store, Subscription};
use std::boxed::Box;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
struct State {
date: Date<Utc>,
@mbrubeck
mbrubeck / randomize-hn.user.js
Last active March 4, 2020 20:05
Randomize Hacker News user script
// ==UserScript==
// @name Randomize Hacker News
// @namespace http://limpet.net/mbrubeck/
// @description Promote random new or low-ranked stories to the Hacker News front page.
// @include http://news.ycombinator.com/
// @include http://news.ycombinator.com/news
// @include https://news.ycombinator.com/
// @include https://news.ycombinator.com/news
// ==/UserScript==
test header_map order_map_fnv std_map_fnv order_map_seahash vec_map
get_100_std 623 613 393 1,511 2,628
get_10_custom_short 103 97 91 259 389
get_10_of_20_std 54 52 39 114 42
hn_hdrs_set_11_get_with_miss 774 739 771 1,062 735
hn_hdrs_set_8_get_many 664 680 701 912 470
hn_hdrs_set_8_get_miss 502 543 616 593 373
insert_100_custom_headers 6,331 5,924 14,043 6,900 28,461
insert_4_std_get_30 381 360 460 580 357
insert_500_custom_headers 30,174 26,153 54,672 32,465 568,644
test basic::get_100_std::header_map ... bench: 623 ns/iter (+/- 145)
test basic::get_100_std::order_map_fnv ... bench: 613 ns/iter (+/- 244)
test basic::get_100_std::order_map_seahash ... bench: 1,511 ns/iter (+/- 237)
test basic::get_100_std::std_map_fnv ... bench: 393 ns/iter (+/- 27)
test basic::get_100_std::vec_map ... bench: 2,628 ns/iter (+/- 147)
test basic::get_10_custom_short::header_map ... bench: 103 ns/iter (+/- 12)
test basic::get_10_custom_short::order_map_fnv ... bench: 97 ns/iter (+/- 13)
test basic::get_10_custom_short::order_map_seahash ... bench: 259 ns/iter (+/- 34)
test basic::get_10_custom_short::std_map_fnv ... bench: 91 ns/iter (+/- 10)
test basic::get_10_custom_short::vec_map ... bench: 389 ns/iter (+/- 32)
@mbrubeck
mbrubeck / parallel-layout.md
Created September 22, 2017 23:48
Parallel layout in Gecko

Parallel Layout in Gecko

Now that Gecko uses Servo's parallel style system, we want to work outward from there. The next phase could be parallel frame construction, and after that, parallel layout using Servo layout code.

Dividing work between Gecko and Servo

We want to ship this work incrementally (every six weeks), without needing to replace the entire layout system at once. There are a few ways we can convert

[package]
name = "pb"
version = "0.1.0"
authors = ["Matt Brubeck <mbrubeck@limpet.net>"]
edition = "2018"
[[bin]]
name = "pb"
path = "main.rs"
[package]
name = "foo"
version = "0.1.0"
authors = ["Matt Brubeck <mbrubeck@limpet.net>"]
edition = "2018"
[dependencies]
[build-dependencies]
smallvec = "0.6"
@mbrubeck
mbrubeck / lib.rs
Last active July 19, 2018 16:05 — forked from pftbest/lib.rs
#![feature(test)]
extern crate test;
trait Max2 {
type Item;
fn max_by_key2<B: Ord, F>(self, f: F) -> Option<Self::Item> where
Self: Sized,
F: FnMut(&Self::Item) -> B;
}
use itertools::zip;
use std::ops::{BitXor, BitXorAssign};
pub fn xor<T>(x: &[T], y: &[T]) -> Vec<T>
where T: BitXor<Output=T> + Copy {
zip(x, y).map(|(a, b)| *a ^ *b).collect()
}
pub fn xor_with<T>(x: &mut [T], y: &[T])
where T: BitXorAssign + Copy {