Skip to content

Instantly share code, notes, and snippets.

View jackmott's full-sized avatar

Jack Mott jackmott

  • Olo
  • Texas,USA
View GitHub Profile
@jackmott
jackmott / SIMDStarterKit.h
Last active January 4, 2024 23:15
A header file to make SIMD intrinsics a bit easier to work with
// 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!)
// 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) }
@jackmott
jackmott / webdev.js
Last active May 11, 2016 19:03
web dev
// 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 August 8, 2016 15:18
Fast Filter for F#
// 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 August 10, 2016 19:13
Faster Filter Take 9,000
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 August 11, 2016 03:55
Faster Array.partition for F#
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 August 12, 2016 12:17
Core lib parallel Array.chose F#
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
@jackmott
jackmott / filter.fs
Last active August 18, 2016 14:03
filter
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 August 19, 2016 18:35
benmarking template
/// 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 August 19, 2016 21:33
experimental filter
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|]