Skip to content

Instantly share code, notes, and snippets.

View manofstick's full-sized avatar

Paul Westcott manofstick

  • Kaiser Trading Group
  • Melbourne, Australia
View GitHub Profile
@manofstick
manofstick / tbm_euler_5.fs
Created April 2, 2017 08:16
TheBurningMonk - Euler - 5
open System.Diagnostics
module ``TheBurningMonk - Euler`` =
// collated from :- https://github.com/theburningmonk/ProjectEuler-FSharp-Solutions/tree/master/ProjectEulerSolutions/ProjectEulerSolutions
// documentation :- http://theburningmonk.com/project-euler-solutions/
open System
open System.Numerics
let inline private validate expected received =
if expected <> received then
@manofstick
manofstick / burning_monk_euler.fs
Last active September 26, 2017 07:22
Seq regression/performance
open System.Diagnostics
#if !INCLUDE_PROJECT_INFO
module ProjectInfo =
let Name = "Unknown"
let AppendResultTo = None
#endif
[<AutoOpen>]
module Helpers =
let countPrimes n =
let rec outer count i =
if i <= n then
let sqrtI = int (floor (sqrt (float i)))
let rec inner j =
if j <= sqrtI then
if i % j <> 0 then
inner (j+1)
else
false
open System.Diagnostics
let sum1 (a:array<_>) total =
total := 0
for i = 0 to a.Length-1 do
total := !total + a.[i]
!total
let sum2 (a:array<_>) total =
total := 0
@manofstick
manofstick / lazy_regression.cs
Created January 17, 2017 08:50
A set of regression tests for lazy
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading;
using System.Reflection;
namespace LazyTest
{
[TestClass]
public class LazyRegressionTests
{
@manofstick
manofstick / seq_test.fs
Created November 2, 2016 21:21
state machine vs piping
open System.Diagnostics
let createViaStateMachine data =
seq {
for item in data do
if item % 13L <> 0L then
let item2 = item * item
if item2 % 11L <> 0L then
yield item2 }
@manofstick
manofstick / seq.fs
Created November 1, 2016 08:08
Backup of SeqComposer
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.FSharp.Collections
#nowarn "52" // The value has been copied to ensure the original is not mutated by this operation
open System
open System.Diagnostics
open System.Collections
open System.Collections.Generic
open Microsoft.FSharp.Core
@manofstick
manofstick / performance.fs
Created October 25, 2016 08:44
Seq Performance Various Sources
open System.Diagnostics
let createSources size f = [
"array", (lazy (Array.init size f :> seq<_>))
"list", (lazy (List.init size f :> seq<_>))
"computation expression", (lazy (seq {
let mutable x = 0
while x < size do
@manofstick
manofstick / chunking.fs
Created October 24, 2016 02:46
Chunking vs Nessos.Streams
open System.Diagnostics
open Nessos.Streams
[<Struct; NoComparison; NoEquality>]
type Chunk<'T> =
[<DefaultValue false>] val mutable _toProcess : int
[<DefaultValue false>] val mutable _1 : 'T
[<DefaultValue false>] val mutable _2 : 'T
[<DefaultValue false>] val mutable _3 : 'T
[<DefaultValue false>] val mutable _4 : 'T
open BenchmarkDotNet.Running
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Configs
open BenchmarkDotNet.Diagnostics.Windows
open BenchmarkDotNet.Jobs
open System.Collections.Generic
open System.Collections
open System