Skip to content

Instantly share code, notes, and snippets.

Jack Mott jackmott

Block or report user

Report or block jackmott

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ndimensionalpoo.fs
// Learn more about F# at
// 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
// 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 / 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 / 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 / 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 / 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 / bench.fs
Created Aug 19, 2016
benmarking template
View bench.fs
/// BenchmarkDotNet Notes:
/// Docs/Github:
/// 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 / filterUltra.fs
Last active Aug 19, 2016
experimental filter
View filterUltra.fs
let filterUltra f (array : 'T[]) =
let inline computeChunk (x:float32) =
let chunkProgression =
match sizeof<'T> * array.Length with
| x when x < 4096 -> [|array.Length|]
| x when x < 65536 -> [|computeChunk 0.25f;computeChunk 0.76f|]
jackmott / bench.cs
Created Aug 23, 2016
C# benchmarks
View bench.cs
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Diagnostics.Windows;
namespace bigo
You can’t perform that action at this time.