Skip to content

Instantly share code, notes, and snippets.

@0x53A
Created May 2, 2017 02:10
Show Gist options
  • Save 0x53A/b8bb15e040d152742fd067ce257e80a2 to your computer and use it in GitHub Desktop.
Save 0x53A/b8bb15e040d152742fd067ce257e80a2 to your computer and use it in GitHub Desktop.
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Jobs
open Paket.Requirements
open Paket.Domain
open Paket
open BenchmarkDotNet.Running
open BenchmarkDotNet.Configs
[<MemoryDiagnoser>]
type ParallelBench () =
let a = {
Name = PackageName("some name")
VersionRequirement = VersionRequirement(VersionRange.Specific(SemVer.Parse("1.0")), PreReleaseStatus.No)
ResolverStrategyForDirectDependencies = None
ResolverStrategyForTransitives = None
Parent = PackageRequirementSource.DependenciesFile("some file")
Graph = []
Sources = []
Settings = InstallSettings.Default
}
let b = {
Name = PackageName("some name")
VersionRequirement = VersionRequirement(VersionRange.Specific(SemVer.Parse("1.0")), PreReleaseStatus.No)
ResolverStrategyForDirectDependencies = None
ResolverStrategyForTransitives = None
Parent = PackageRequirementSource.DependenciesFile("some other file") // <-- the only difference
Graph = []
Sources = []
Settings = InstallSettings.Default
}
[<Benchmark>]
member self.Old() =
PackageRequirement.Compare(a, b, None, 0, 0)
[<Benchmark>]
member self.New() =
ParallelBench.CompareNew(a, b, None, 0, 0)
static member CompareNew(x:PackageRequirement,y:PackageRequirement,startWithPackage:PackageFilter option,boostX,boostY) =
if obj.ReferenceEquals(x, y) then 0 else
let c = compare
(not x.VersionRequirement.Range.IsGlobalOverride,x.Depth)
(not y.VersionRequirement.Range.IsGlobalOverride,y.Depth)
if c <> 0 then c else
let c = match startWithPackage with
| Some filter when filter.Match x.Name -> -1
| Some filter when filter.Match y.Name -> 1
| _ -> 0
if c <> 0 then c else
let c = -compare x.ResolverStrategyForDirectDependencies y.ResolverStrategyForDirectDependencies
if c <> 0 then c else
let c = -compare x.ResolverStrategyForTransitives y.ResolverStrategyForTransitives
if c <> 0 then c else
let c = compare boostX boostY
if c <> 0 then c else
let c = -compare x.VersionRequirement y.VersionRequirement
if c <> 0 then c else
let c = compare x.Settings.FrameworkRestrictions y.Settings.FrameworkRestrictions
if c <> 0 then c else
let c = compare x.Parent y.Parent
if c <> 0 then c else
let c = compare x.Name y.Name
if c <> 0 then c else 0
[<EntryPoint>]
let main argv =
let job =
Job.RyuJitX64
//.WithLaunchCount(1)
//.WithWarmupCount(2)
//.WithTargetCount(3)
//.WithInvocationCount(640)
let summary = BenchmarkRunner.Run<ParallelBench>(ManualConfig.Create(DefaultConfig.Instance).With(job)) |> ignore //
0 // return an integer exit code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment