Giter VIP home page Giter VIP logo

Comments (5)

cathei avatar cathei commented on May 26, 2024

Here is the benchmark source I've tested

Results:

BenchmarkDotNet=v0.13.2, OS=macOS Monterey 12.3 (21E230) [Darwin 21.4.0]
Apple M1 Pro, 1 CPU, 10 logical and 10 physical cores
.NET SDK=7.0.101
  [Host]     : .NET 6.0.2 (6.0.222.6406), Arm64 RyuJIT AdvSIMD
  DefaultJob : .NET 6.0.2 (6.0.222.6406), Arm64 RyuJIT AdvSIMD

Method Mean Error StdDev Ratio Allocated Alloc Ratio
PointerAccess 57.97 ms 0.772 ms 0.722 ms 0.46 154 B 0.23
NBFixed 59.77 ms 0.258 ms 0.215 ms 0.47 75 B 0.11
NBWithSize 240.70 ms 0.737 ms 0.689 ms 1.90 893 B 1.33
NBWithSentinel 127.20 ms 0.262 ms 0.233 ms 1.00 168 B 0.25
NBWithSentinelAndSize 126.93 ms 0.148 ms 0.123 ms 1.00 670 B 1.00

Weirdly, removing using block but not replacing SIZE makes it even slower. I think it is related to static constructor for SIZE while the code got inlined.

from svelto.ecs.

cathei avatar cathei commented on May 26, 2024

I've added benchmark result for .NET 7 and Mono to the link, and it seems accessing with pointer is much performant for those. I think using T* instead of Unsafe APIs should be considered alongside.

from svelto.ecs.

sebas77 avatar sebas77 commented on May 26, 2024

I am pretty sure (confirmed with sharplab.io) that in release compilation the using will not generate a try catch if it's empty, in any case atm that line can be commented out. However the static field killed me, I have to think a lot about it as I use this everywhere in the code. Why is your benchmarking alocating at all?

from svelto.ecs.

cathei avatar cathei commented on May 26, 2024

that in release compilation the using will not generate a try catch if it's empty

Main issue would be that using prevents inlining. I've tested with this SharpLab, and if you see the assembly it prevents inlining to CallWithUsing while method WithUsing does not contain try-finally.

Why is your benchmarking alocating at all?

It only happens if I put a very big number for Count for some reason. It happens on irrelevant benchmarks as well. I think it's MemoryDiagnoser issue.

from svelto.ecs.

sebas77 avatar sebas77 commented on May 26, 2024

according my profiing Unsafe.As is as fast as using T*

from svelto.ecs.

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.