Skip to content

Instantly share code, notes, and snippets.

Jack Mott jackmott

View GitHub Profile
@jackmott
jackmott / SIMDStarterKit.h
Last active May 25, 2020
A header file to make SIMD intrinsics a bit easier to work with
View SIMDStarterKit.h
// A header file to get you set going with Intel SIMD instrinsic programming.
// All necessary header files are inlucded for SSE2, SSE41, and AVX2
// Macros make the intrinsics easier to read and generic so you can compile to
// SSE2 or AVX2 with the flip of a #define
#define SSE2 //indicates we want SSE2
#define SSE41 //indicates we want SSE4.1 instructions (floor and blend is available)
#define AVX2 //indicates we want AVX2 instructions (double speed!)
View ndimensionalpoo.fs
// Learn more about F# at http://fsharp.org
// See the 'F# Tutorial' project for more help.
open MathNet.Numerics
open System.Numerics
//create a fractional approximation of pi
let rec series n q =
seq {
yield q * 4N / n
yield! series (n + 2N) (q * -1N) }
View webdev.js
// All you want to do is take a table in the database
// and show it as a table in the browser.
// How hard could it be?
// First you gotta know SQL or whatever other language/syntax your
// database uses to query it
var query = "SELECT TOP 100 * FROM THINGS ORDER BY DATE"
// Then you gotta import and learn to use some database driver to talk to your database
// Or alternatively learn to use its REST api and work with whatever format it returns
@jackmott
jackmott / fastFilter.fs
Last active Aug 8, 2016
Fast Filter for F#
View fastFilter.fs
// Faster than the core lib filter in most scenarios.
// Core lib may be faster when filtering about half the data
// and the filtered data is randomy distributed in the array.
// Even in cases where it is a little slower, it allocates a lot
// less. Relieving GC overhead.
let inline filter (f: ^T -> bool) (array: ( ^T)[]) =
let len = array.Length
if array = null then invalidArg "array" "Array can not be null."
if len = 0 then invalidArg "array" "Array can not be empty."
@jackmott
jackmott / filter.fs
Created Aug 10, 2016
Faster Filter Take 9,000
View filter.fs
let filter f (array: 'T[]) =
checkNonNull array
if sizeof<'T> < 4 then
let tmp = Array.zeroCreate array.Length
let mutable count = 0
for i = 0 to array.Length - 1 do
let x = array.[i]
if f x then
@jackmott
jackmott / partition.fs
Last active Aug 11, 2016
Faster Array.partition for F#
View partition.fs
let arrayPartition f (array: _[]) =
checkNonNull array
//Hold both arrays in one of exact length
let res = Array.zeroCreate array.Length
let mutable upCount = 0
let mutable downCount = array.Length-1
for i = 0 to array.Length-1 do
let x = array.[i]
if f x then
@jackmott
jackmott / choose.fs
Created Aug 12, 2016
Core lib parallel Array.chose F#
View choose.fs
let choose f (array: 'T[]) =
let inputLength = array.Length
let isChosen : bool [] = Array.zeroCreate inputLength
let results : 'U [] = Array.zeroCreate inputLength
Parallel.For(0, inputLength, (fun i ->
match f array.[i] with
View filter.fs
let filterNew f (array: _[]) =
checkNonNull "array" array
let mutable i = 0
while i < array.Length && not (f array.[i]) do
i <- i + 1
if i <> array.Length then
@jackmott
jackmott / bench.fs
Created Aug 19, 2016
benmarking template
View bench.fs
/// BenchmarkDotNet Notes:
/// Docs/Github: https://github.com/PerfDotNet/BenchmarkDotNet#getting-started
///
/// This benchmarking suite will perform JIT warmups, collect system environment data
/// run multiple trials, and produce convenient reports.
/// You will find csv, markdown, and and html versions of the reports in .\BenchmarkDotNet.Artifacts\results
/// after running the tests.
///
/// Be sure to run tests in Release mode, optimizations on, etc.
@jackmott
jackmott / filterUltra.fs
Last active Aug 19, 2016
experimental filter
View filterUltra.fs
let filterUltra f (array : 'T[]) =
let inline computeChunk (x:float32) =
int((float32)array.Length*x)
let chunkProgression =
match sizeof<'T> * array.Length with
| x when x < 4096 -> [|array.Length|]
| x when x < 65536 -> [|computeChunk 0.25f;computeChunk 0.76f|]
You can’t perform that action at this time.