Skip to content

Instantly share code, notes, and snippets.

Avatar

Yohaï-Eliel Berreby yberreby

View GitHub Profile
@yberreby
yberreby / results
Created Sep 4, 2016
Rust Benchmark - printing to stdout
View results
print_macro: 105 ns/iter (+/- 20)
print_macro_locked_stdoutbench: 87 ns/iter (+/- 22)
direct_locked_stdout: 17 ns/iter (+/- 2)
direct_unlocked_stdout: 51 ns/iter (+/- 9)
View strange_opt.rs
#![feature(test)]
extern crate test;
use test::Bencher;
const LARGE_NUMBER: i32 = 1_000_000;
#[bench]
fn bench_even_imperative(b: &mut Bencher) {
b.iter(|| {
let mut list = Vec::with_capacity(LARGE_NUMBER as usize / 2 + 1);
View gist:09ff02b76affb254c8f9
### Keybase proof
I hereby claim:
* I am filsmick on github.
* I am yberreby (https://keybase.io/yberreby) on keybase.
* I have a public key whose fingerprint is 0D2A 6DC4 BFB5 8105 832B A469 803E 20B3 F3E1 9D9F
To claim this, I am signing this object:
View gist:38d01523cfdbcdd9c97f
#![feature(rt)]
#![feature(unmarked_api)]
use std::thread;
use std::any::Any;
use std::rt::unwind::set_panic_handler;
fn main() {
// Use the default handler
panic!("Something's wrong"); // Prints "thread '<main>' panicked at 'Something's wrong', /Users/yohai/code/panic_handlers_test.rs:10"
@yberreby
yberreby / mod.rs
Created Jun 28, 2015
src/libstd/rt/unwind/mod.rs - panic handler PoC
View mod.rs
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
View gist:084c10fd23d0d6495b11
client_cargo/../src/sector_client.rs:121:32: 121:46 error: no method named `should_close` found for type `core::cell::Ref<'_, glutin_window::GlutinWindow>` in the current scope
client_cargo/../src/sector_client.rs:121 if window.borrow().should_close() { break; }
^~~~~~~~~~~~~~
client_cargo/../src/sector_client.rs:121:32: 121:46 help: items from traits can only be used if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
client_cargo/../src/sector_client.rs:121:32: 121:46 help: candidate #1: use `window::Window`
client_cargo/../src/sector_client.rs:161:49: 161:50 error: mismatched types:
expected `event::event::Event<input::Input>`,
found `event::event::Event`
(expected enum `input::Input`,
found a different enum `input::Input`) [E0308]
@yberreby
yberreby / array_binsearch.cpp
Created Sep 11, 2014
Binary search implementation for native arrays
View array_binsearch.cpp
#include <iostream>
#include <vector>
using namespace std;
template <typename T>
int binary_search(const T& elem, const T* a, const size_t length) {
int middleIndex = length / 2;
T midpoint = a[middleIndex];
if (midpoint == elem) return middleIndex;