Skip to content

Instantly share code, notes, and snippets.

View saethlin's full-sized avatar
🦀

Ben Kimock saethlin

🦀
View GitHub Profile
@saethlin
saethlin / process_bench.py
Created January 10, 2017 19:47
Rough benchmark to show Python multiprocessing overhead from inter-process communication
import time
import threading
import multiprocessing
from numba import jit
import numpy as np
thing1 = np.empty((4000, 4000))
thing2 = np.empty((4000, 4000))
@saethlin
saethlin / leapfrog.c
Last active April 25, 2017 22:22
C and Rust Leapfrog Comparison
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
typedef struct {
double x, y, z;
} Point;
use std::io::BufRead;
fn main() {
let file = std::fs::File::open("resources/solarccf.txt").unwrap();
let buf = std::io::BufReader::new(file);
let (rv_iter, quiet_iter, active_iter) = buf
.lines()
.skip(2)
.map(|l| l.unwrap().split_whitespace())
extern crate rand; // from cargo, not the experimental one
use rand::distributions::IndependentSample;
pub struct ParticleVector {
data: Vec<f64>,
size: usize,
}
#[repr(C)]
struct Point {
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef struct Point {
double x;
double y;
double z;
} Point;
@saethlin
saethlin / holy_shit.asm
Created May 14, 2017 02:28
leapfrog asm with numpy operator overloading
----------------------------------ASSEMBLY nrt----------------------------------
.text
.file "<string>"
.globl nrt_atomic_add
.p2align 4, 0x90
.type nrt_atomic_add,@function
nrt_atomic_add:
movl $1, %eax
lock xaddq %rax, (%rdi)
addq $1, %rax
@saethlin
saethlin / leapfrog_notmadness.asm
Created May 14, 2017 02:33
leapfrog with some explicit loops
----------------------------------ASSEMBLY nrt----------------------------------
.text
.file "<string>"
.globl nrt_atomic_add
.p2align 4, 0x90
.type nrt_atomic_add,@function
nrt_atomic_add:
movl $1, %eax
lock xaddq %rax, (%rdi)
addq $1, %rax
Point:
x, y, z f64
Particle:
position, velocity, acceleration Point
mass f64
particles = SoA(Particle, 100)
particles.position = random(0.03, 0.03)
particles.mass = 1e-6
@saethlin
saethlin / derpy.rs
Created May 24, 2017 04:38
Clippy? Are you okay?
warning: use of `unwrap_or` followed by a function call
--> src/commands/ls.rs:30:33
|
30 | let dir = Path::new(options.value_of_os("directory").unwrap_or(state.directory.as_os_str()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this `options.value_of_os("directory").unwrap_or_else(|| state.directory.as_os_str())`
|
= note: #[warn(or_fun_call)] on by default
= help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#or_fun_call
@saethlin
saethlin / CircularBuffer.rs
Created May 24, 2017 22:33
A fixed-size circular buffer for use in implementing shell history
struct CircularBuffer<T> {
buffer: Vec<T>,
head: usize,
tail: usize,
}
impl <T: Default> CircularBuffer<T>{
pub fn new(size: usize) -> Self {
CircularBuffer {
buffer: vec![Default::default(); size],