Skip to content

Instantly share code, notes, and snippets.

use std::thread;
static NEED: [u8; 21] = [43, 25, 20, 16, 15, 13, 12, 12, 11, 10, 10, 8, 8, 4, 4, 3, 3, 1, 1, 1, 1];
fn is_ok<F>(pred: F) -> bool
where F: Fn(u8) -> u8
{
let mut counts = [0; 256];
for tok in 0..256 {
counts[pred(tok as u8) as usize] += 1;
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import random
# Make this higher when you want better graphs
iters = 100
def trunc(x):
return x % (2**64)
def test_row(f, swaps):
seen = set()
time: 0.594; rss: 322MB parsing
time: 0.000; rss: 322MB recursion limit
time: 0.000; rss: 322MB crate injection
time: 0.000; rss: 322MB plugin loading
time: 0.000; rss: 322MB plugin registration
time: 0.295; rss: 349MB expansion
time: 0.000; rss: 349MB maybe building test harness
time: 0.012; rss: 349MB maybe creating a macro crate
time: 0.000; rss: 349MB checking for inline asm in case the target doesn't support it
time: 0.023; rss: 349MB complete gated feature checking
@Veedrac
Veedrac / battle.py
Created July 8, 2016 15:26
Example teaching program
import random
hero_hp = random.randint(500, 1000)
minotaur_hp = random.randint(1000, 2000)
damage_base = 100
heal_base = 50
while True:
print("Hero HP: {}".format(hero_hp))
#include <algorithm>
class X {
private:
std::size_t size;
int *data;
public:
// You still keep the main three, the constructor,
// copy constructor and destructor,
#include "benchmark/benchmark.h"
#include <algorithm>
class X {
private:
std::size_t size;
int *data;
public:
/**
* This code uses std.experimental.ndslice to take the mean of the columns in
* a 2d 100x1000 array and creates a benchmark of that code.
*
* My mean running time is about 1.2 ms.
*
* If we compare this code to the Numpy equivalent,
*
* import numpy
* data = numpy.arange(100000, dtype="int32").reshape((100, 1000))
[
{
"caption": "SublimeREPL: Python 3",
"command": "run_existing_window_command", "args":
{
"id": "repl_python3",
"file": "config/Python3/Main.sublime-menu"
}
},
{
@Veedrac
Veedrac / main.rs
Created December 27, 2015 20:21
Naïve (inaccurate, prone to overflow) floating point parser vs. Rust builtin parser benchmark
#![feature(test)]
extern crate test;
use std::f64;
pub fn parse_builtin(string: &str) -> Option<f64> {
string.parse().ok()
}