Giter VIP home page Giter VIP logo

Comments (3)

dadhi avatar dadhi commented on July 18, 2024

The first results are here:
https://github.com/dadhi/ImTools/blob/master/playground/ImTools.UnionCsVsFsBenchmarks/Program.fs

  • Test sum of records as a more general case
  • Lengthy collection to compare
  • Compare vs union.Match
  • Sepate benchmark for collection creation

Remarks regarding F#:

  • Type names like val, _ invalid in F# context
  • Sub-typed internal classes are not accessible

from imtools.

dadhi avatar dadhi commented on July 18, 2024

New naming proposal:

  • All nested types are lowercase
  • External types are single letter better not conflicting with something else
  • U2, U3, .. for the unnamed unions
public abstract class Case<TName, T>
{
   public readonly struct @case : I<T>, IEq<value>
   {
       public T Value { get; }
       //...
   }
}

public sealed class U2<A, B> : U<Empty, A, B> {}
public abstract class U<TName, A, B>
{
   public interface union
   {
       R Match<A, B, R>(Func<A, R> fa...);
   }
   public readonly struct case1 : union, I<A>, IEq<case1>
   {
      public A Value { get; }
      //...
   }
}

from imtools.

dadhi avatar dadhi commented on July 18, 2024

Results:

BenchmarkDotNet=v0.12.0, OS=Windows 10.0.18362
Intel Core i7-8750H CPU 2.20GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
.NET Core SDK=3.0.100
  [Host]     : .NET Core 3.0.0 (CoreCLR 4.700.19.46205, CoreFX 4.700.19.46214), X64 RyuJIT DEBUG
  DefaultJob : .NET Core 3.0.0 (CoreCLR 4.700.19.46205, CoreFX 4.700.19.46214), X64 RyuJIT


|                                     Method |      Mean |    Error |   StdDev | Ratio | RatioSD |  Gen 0 | Gen 1 | Gen 2 | Allocated |
|------------------------------------------- |----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:|
|                                     FSharp |  12.49 ns | 0.031 ns | 0.029 ns |  1.00 |    0.00 |      - |     - |     - |         - |
|                   CSharp_named_case_struct |  15.43 ns | 0.085 ns | 0.080 ns |  1.24 |    0.01 |      - |     - |     - |         - |
|         CSharp_named_case_struct_tag_match |  15.00 ns | 0.162 ns | 0.152 ns |  1.20 |    0.01 |      - |     - |     - |         - |
| CSharp_named_case_struct_match_I_interface | 248.44 ns | 4.045 ns | 3.784 ns | 19.89 |    0.29 |      - |     - |     - |         - |
|      CSharp_named_case_struct_Match_method | 181.99 ns | 0.563 ns | 0.527 ns | 14.57 |    0.06 | 0.1733 |     - |     - |     816 B |

from imtools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.