Giter Club home page Giter Club logo

benchmarkemptystring's Introduction


Here is benchmark results for str == "" vs str.Length == 0

  .NET Core SDK=3.1.300
  [Host]     : .NET Core 3.1.4 (CoreCLR 4.700.20.20201, CoreFX 4.700.20.22101), X64 RyuJIT
  DefaultJob : .NET Core 3.1.4 (CoreCLR 4.700.20.20201, CoreFX 4.700.20.22101), X64 RyuJIT
Method Mean Error StdDev
Test_1_000_000_EqualityOperator 15,394,460.9 ns 302,780.33 ns 488,933.80 ns
Test_1_000_000_StringLength 10,515,186.1 ns 123,536.86 ns 103,158.88 ns
Test_1_000_EqualityOperator 6,535.9 ns 84.80 ns 75.18 ns
Test_1_000_StringLength 3,056.8 ns 33.96 ns 30.11 ns
Test_100_EqualityOperator 672.1 ns 7.37 ns 5.75 ns
Test_100_StringLength 327.1 ns 3.92 ns 3.67 ns

Benchmark.cs


Replace str == "" and str == string.Empty with str.Length == 0

+it will increase perfomance a little bit -perhaps it is less readable

Also, You can add

# CA1820: Test for empty strings using string length
dotnet_diagnostic.CA1820.severity = error

to avoid using str == "" in the future

benchmarkemptystring's People

Contributors

makeprojectgreatagain avatar

Watchers

 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.