Skip to content

Instantly share code, notes, and snippets.

Avatar

Jon Harrop jdh30

View GitHub Profile
View SciMark2 Monte Carlo in F#
module SciMark2
module Random =
let m = Array.create 17 0
let mutable i = 4
let mutable j = 16
let mdig = 32
let m1 = (1 <<< mdig - 2) + ((1 <<< mdig - 2) - 1)
let m2 = 1 <<< mdig / 2
let dm1 = 1.0 / float m1
View SciMark2 Monte Carlo in OCaml
module Random = struct
let m = Array.create 17 0
let i = ref 4
let j = ref 16
let mdig = 32
let m1 = (1 lsl (mdig - 2)) + (1 lsl (mdig - 2)) - 1
let m2 = 1 lsl (mdig / 2)
let dm1 = 1.0 /. (2. ** float(mdig-1) -. 1.)
let nextDouble() =
@jdh30
jdh30 / k-nucleotide
Created Jun 13, 2015
This is a drop-in replacement for some of the very poor code given on The Computer Language Benchmarks Game
View k-nucleotide
// F# code for the k-nucleotide task
// This is ~3.6x faster than the solution currently on The Computer Language Benchmarks Game.
// The optimisations are described in detail in the F# Journal article:
// "Optimising k-nucleotide" -- http://fsharpnews.blogspot.com/2013/08/optimizing-k-nucleotide.html
module Sub =
let maxLength = 29
let lengthPos = maxLength*2
let bits length = (1UL <<< (2*length)) - 1UL
let codeMask = bits maxLength
@jdh30
jdh30 / gist:c5ba4c52b46d2c77fa96
Last active Aug 29, 2015
Code for my CNC mill
View gist:c5ba4c52b46d2c77fa96
#define X_STEP_PIN 54
#define X_DIR_PIN 55
#define X_ENABLE_PIN 38
#define X_MIN_PIN 3
#define X_MAX_PIN 2
#define Y_STEP_PIN 60
#define Y_DIR_PIN 61
#define Y_ENABLE_PIN 56
#define Y_MIN_PIN 14
@jdh30
jdh30 / gist:bc1794232ac584db9baa
Created Aug 29, 2015
List-based n-queens solver with mark-sweep GC written in C++
View gist:bc1794232ac584db9baa
#include <vector>
#include <iostream>
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include "Allocator.h"
#include "MarkSweep.h"
#define OPTIMIZED
#define SHADOWSTACK
@jdh30
jdh30 / neighbors2.rs
Created Mar 28, 2016
Rust implementation of a HashSet benchmark from the F# Journal
View neighbors2.rs
use std::collections::HashSet;
use std::hash::BuildHasherDefault;
use std::default::Default;
use std::hash::Hasher;
pub struct FnvHasher(u64);
impl Default for FnvHasher {
#[inline]
@jdh30
jdh30 / neighbors2.fs
Last active Apr 2, 2016
F# implementation of a HashSet benchmark from the F# Journal with unboxed tuples
View neighbors2.fs
type [<Struct>] P =
val i : int
val j : int
new(i, j) = {i=i; j=j}
let cmp =
{ new System.Collections.Generic.IEqualityComparer<P> with
member __.Equals(this, that) =
this.i = that.i && this.j = that.j
@jdh30
jdh30 / neighbors.cpp
Created Mar 28, 2016
C++ implementation of a HashSet benchmark from the F# Journal
View neighbors.cpp
#include "stdafx.h"
#include <iostream>
#include <unordered_set>
using namespace std;
typedef pair<int, int> P;
template <class T> struct MyHash;
template<> struct MyHash<P>
@jdh30
jdh30 / neighbors3.rs
Last active Jun 21, 2016
Neighbors benchmark in Rust using a simpler hash function Raw
View neighbors3.rs
use std::collections::HashSet;
use std::hash::BuildHasherDefault;
use std::default::Default;
use std::hash::Hasher;
pub struct FnvHasher(u64);
impl Default for FnvHasher {
#[inline]
@jdh30
jdh30 / neighbors3.fs
Last active Jun 21, 2016
Neighbors benchmark in F# using the simple hash function from a Rust version
View neighbors3.fs
open System.Collections.Generic
type [<Struct>] P =
val i : int
val j : int
new(i, j) = {i=i; j=j}
let cmp =
{ new System.Collections.Generic.IEqualityComparer<P> with
member __.Equals(this, that) =
You can’t perform that action at this time.