Code Monkey home page Code Monkey logo

benchmark-localfunctions-vs-lambdas's Introduction

Benchmark LocalFunctions vs Lambdas

Benchmark the statements in the following article https://docs.microsoft.com/en-us/dotnet/csharp/local-functions-vs-lambdas

 public static int LambdaFactorial(int n)
        {
            Func<int, int> nthFactorial = default(Func<int, int>);
            nthFactorial = (number) => (number < 2) ?
                1 : number * nthFactorial(number - 1);
            return nthFactorial(n);
        }

vs

   public static int LocalFunctionFactorial(int n)
        {
            return nthFactorial(n);
            int nthFactorial(int number) => (number < 2) ?
                1 : number * nthFactorial(number - 1);
        }

Results

BenchmarkDotNet=v0.10.6, OS=Windows 10 Redstone 1 (10.0.14393)
Processor=Intel Core i5-4590 CPU 3.30GHz (Haswell), ProcessorCount=4
Frequency=3215225 Hz, Resolution=311.0202 ns, Timer=TSC
  [Host]     : Clr 4.0.30319.42000, 32bit LegacyJIT-v4.7.2053.0
  DefaultJob : Clr 4.0.30319.42000, 32bit LegacyJIT-v4.7.2053.0
Method N Mean Error StdDev Min Max Gen 0 Allocated
LambdaFactorial 3 14.707 ns 0.1897 ns 0.1775 ns 14.443 ns 15.023 ns 0.0140 44 B
LocalFunctionFactorial 3 4.111 ns 0.0469 ns 0.0439 ns 4.057 ns 4.196 ns - 0 B
LambdaFactorial 10 31.992 ns 0.0707 ns 0.0591 ns 31.917 ns 32.090 ns 0.0139 44 B
LocalFunctionFactorial 10 15.327 ns 0.0622 ns 0.0582 ns 15.230 ns 15.424 ns - 0 B
LambdaFactorial 20 62.756 ns 0.0966 ns 0.0698 ns 62.631 ns 62.878 ns 0.0139 44 B
LocalFunctionFactorial 20 37.762 ns 0.2754 ns 0.2576 ns 37.210 ns 38.106 ns - 0 B

Benchmarked with BenchmarkDotNet

benchmark-localfunctions-vs-lambdas's People

Contributors

adrianiftode avatar

Watchers

 avatar  avatar

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.