Skip to content

Instantly share code, notes, and snippets.

View gist:d53a6c2795890f94fa66e0bafb0bf73b
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 Jul 8, 2016
Example teaching program
View battle.py
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))
View main.d
/**
* 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 Dec 27, 2015
Naïve (inaccurate, prone to overflow) floating point parser vs. Rust builtin parser benchmark
View main.rs
#![feature(test)]
extern crate test;
use std::f64;
pub fn parse_builtin(string: &str) -> Option<f64> {
string.parse().ok()
}
View common.rs
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 {
View gist:91f47e67ea0459564d04
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:
View r.rb
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}."
View copy-and-move-bench.cpp
#include "benchmark/benchmark.h"
#include <algorithm>
class X {
private:
std::size_t size;
int *data;
public:
View clang++
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));
View copy-and-move.cpp
#include <algorithm>
class X {
private:
std::size_t size;
int *data;
public:
// You still keep the main three, the constructor,
// copy constructor and destructor,