Skip to content

Instantly share code, notes, and snippets.

pub trait InternalIterator {
type Item;
fn each<F>(&mut self, mut f: F) -> bool
where F: FnMut(Self::Item) -> bool;
}
impl<I> InternalIterator for I
where I: Iterator,
{
type Item = I::Item;
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))
/**
* 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))
@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()
}
pub const WIDTH: usize = 7;
pub const HEIGHT: usize = 6;
pub const MAX_DEPTH: i32 = 7;
pub const ORANGE_WINS: i32 = 1000000;
pub const YELLOW_WINS: i32 = -ORANGE_WINS;
// Couldn't resist changing the type of this
pub type Board = [[i8; WIDTH]; HEIGHT];
pub fn other_color(color:i8) -> i8 {
def fibonacci(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fibonacci(n - 1) + fibonacci(n - 2)
def fibonacci(n):
if n == 0:
require 'prime'
class Integer
# Make a lazy enumerator of the lower half of factors of self
def half_factors
(1..Math.sqrt(self) + 1).lazy.select { |n| (self % n).zero? }
end
end
puts "Started at #{Time.now}."
#include "benchmark/benchmark.h"
#include <algorithm>
class X {
private:
std::size_t size;
int *data;
public:
cpp.cpp:44:18: error: non-const lvalue reference to type 'X' cannot bind to a temporary of type
'typename std::remove_reference<X &>::type' (aka 'X')
swap(std::move(other));
^~~~~~~~~~~~~~~~
cpp.cpp:8:22: note: passing argument to parameter 'other' here
void swap(X& other) noexcept
^
cpp.cpp:65:18: error: non-const lvalue reference to type 'X' cannot bind to a temporary of type
'typename std::remove_reference<X &>::type' (aka 'X')
swap(std::move(rhs));