Skip to content

Instantly share code, notes, and snippets.

@adamchester
Created December 28, 2015 06:50
Show Gist options
  • Save adamchester/cce35708325de31b233d to your computer and use it in GitHub Desktop.
Save adamchester/cce35708325de31b233d to your computer and use it in GitHub Desktop.
AutoFixture NoSpecimen Perf (Singleton vs. new Instance)
#r "./bin/NoSpecimenNewInst/lib/net40/Ploeh.AutoFixture.dll"
printfn "%A" typeof<Ploeh.AutoFixture.Fixture>.AssemblyQualifiedName
let createWithNoSpecNewInst<'T> =
let fixture = Ploeh.AutoFixture.Fixture()
fun () -> fixture.Create(typeof<'T>, Ploeh.AutoFixture.Kernel.SpecimenContext(fixture)) :?> 'T
#r "./bin/NoSpecimenSingleton/lib/net40/Ploeh.AutoFixture.dll"
printfn "%A" typeof<Ploeh.AutoFixture.Fixture>.AssemblyQualifiedName
let noSpecimenSingleton = typeof<Ploeh.AutoFixture.Kernel.NoSpecimen>
let createWithNoSpecSingleton<'T> =
let fixture = Ploeh.AutoFixture.Fixture()
fun () -> fixture.Create(typeof<'T>, Ploeh.AutoFixture.Kernel.SpecimenContext(fixture)) :?> 'T
let noSpecimenNewInst = typeof<Ploeh.AutoFixture.Kernel.NoSpecimen>
(*
printfn "%A" (createWithNoSpecSingleton<System.String>())
printfn "%A" (createWithNoSpecSingleton<System.Int32>())
printfn "%A" (createWithNoSpecNewInst<System.String>())
printfn "%A" (createWithNoSpecNewInst<System.Int32>())
*)
#I "packages/PerfUtil/lib/net40"
#r "perfutil"
open PerfUtil
type INoSpecPeftTest =
inherit ITestable
abstract Run : unit -> unit
let createTest name testF = { new INoSpecPeftTest with
member __.Name = name
member __.Run () = testF ()
member __.Fini () = ()
member __.Init () = () }
let createSingletonTest<'T> () =
createTest ("Singleton "+typeof<'T>.Name) (createWithNoSpecSingleton<'T> >> ignore)
let createNewInstTest<'T> () =
createTest ("New Inst "+typeof<'T>.Name) (createWithNoSpecNewInst<'T> >> ignore)
let singletonInt = createSingletonTest<int>()
let newInstInt = createNewInstTest<int>()
let comparer = ImplementationComparer(singletonInt, [newInstInt], warmup=true, verbose=true, throwOnError=false)
comparer.Run ((fun i -> i.Run()), id="S vs. N <int>", repeat=10000)
type ComplexWithLots = {
AString: string
AnInt: int
AFloat: float
ADecimal: decimal }
let singletonComplexWithLots = createSingletonTest<ComplexWithLots>()
let newInstComplexWithLots = createNewInstTest<ComplexWithLots>()
let comparer2 = ImplementationComparer(singletonComplexWithLots, [newInstComplexWithLots], warmup=true, verbose=true, throwOnError=false)
comparer2.Run ((fun i -> i.Run()), id="S vs. N <Complex>", repeat=10000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment