AntonOresten / DynamicStructs.jl

Structs and dictionaries had a baby
MIT License
3 stars 1 forks source link

Faster propertynames when no dynamic properties are present #7

Closed Tortar closed 2 months ago

Tortar commented 2 months ago
julia> using DynamicStructs, BenchmarkTools

julia> @dynamic struct Spaceship
           name::String
       end

julia> ship = Spaceship("Hail Mary")
Spaceship:
  1 field:
    name::String = "Hail Mary"
  no properties:

julia> @benchmark propertynames($ship)

#now
BenchmarkTools.Trial: 10000 samples with 1000 evaluations.
 Range (min … max):  3.366 ns … 9.157 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     3.417 ns             ┊ GC (median):    0.00%
 Time  (mean ± σ):   3.428 ns ± 0.184 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

                 ▂         ▇█                                
  ▂▁▁▁▁▇▁▁▁▁▄▁▁▁▁█▁▁▁▁▄▃▁▁▁██▁▁▁▇▇▁▁▁▃▄▁▁▁▁▄▁▁▁▁▂▁▁▁▁▄▁▁▁▁▂ ▃
  3.37 ns        Histogram: frequency by time       3.48 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

#before
BenchmarkTools.Trial: 10000 samples with 961 evaluations.
 Range (min … max):   87.211 ns … 449.909 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     110.210 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   111.196 ns ±  10.671 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

                                        ▁▃▇█▇█▇▄▂▁▁              
  ▂▁▁▁▁▁▁▁▁▁▂▂▂▂▁▁▂▂▁▁▁▁▁▁▁▁▁▁▁▁▂▂▂▂▃▄▆████████████▇▇▆▅▄▄▃▃▃▂▂▂ ▄
  87.2 ns          Histogram: frequency by time          119 ns <

 Memory estimate: 32 bytes, allocs estimate: 2.
codecov[bot] commented 2 months ago

Welcome to Codecov :tada:

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered :open_umbrella:

AntonOresten commented 2 months ago

Neat! I hadn't thought of this.

Well done, and thanks for contributing!

Tortar commented 2 months ago

thanks for the package, as I said I think it can be very useful! Actually I'm trying to push for its integration in Agents.jl: https://github.com/JuliaDynamics/Agents.jl/issues/1070, let's see how it goes :-)