JuliaCollections / IterTools.jl

Common functional iterator patterns
Other
153 stars 29 forks source link

Added properties and propertyvalues iterators #61

Closed rofinn closed 5 years ago

rofinn commented 5 years ago

This is pretty similar to https://github.com/JuliaCollections/IterTools.jl/pull/46 and has similar performance characteristics (e.g., faster with mixed value types at the cost of being slower when the value types are all the same).

iamed2 commented 5 years ago

Can you post the benchmark comparisons here for future reference?

rofinn commented 5 years ago
julia> using BenchmarkTools, IterTools
[ Info: Recompiling stale cache file /Users/rory/.julia/compiled/v1.0/IterTools/hhnii.ji for IterTools [c8e1da08-722c-5040-9ed9-7db0dc04731e]

julia> f1(x) = ((n, getproperty(x, n)) for n in propertynames(x))
f1 (generic function with 1 method)

julia> f2(x) = properties(x)
f2 (generic function with 1 method)

julia> v = (a = 1, b = nothing, c = "foo")
(a = 1, b = nothing, c = "foo")

julia> @benchmark collect(f1($v))
BenchmarkTools.Trial:
  memory estimate:  704 bytes
  allocs estimate:  14
  --------------
  minimum time:     3.761 μs (0.00% GC)
  median time:      3.933 μs (0.00% GC)
  mean time:        4.532 μs (9.43% GC)
  maximum time:     3.364 ms (99.76% GC)
  --------------
  samples:          10000
  evals/sample:     8

julia> @benchmark collect(f2($v))
BenchmarkTools.Trial:
  memory estimate:  384 bytes
  allocs estimate:  10
  --------------
  minimum time:     2.614 μs (0.00% GC)
  median time:      2.723 μs (0.00% GC)
  mean time:        2.918 μs (2.97% GC)
  maximum time:     871.587 μs (99.37% GC)
  --------------
  samples:          10000
  evals/sample:     9

julia> v = (a = 1, c = 2.5)
(a = 1, c = 2.5)

julia> @benchmark collect(f1($v))
BenchmarkTools.Trial:
  memory estimate:  720 bytes
  allocs estimate:  15
  --------------
  minimum time:     4.800 μs (0.00% GC)
  median time:      5.049 μs (0.00% GC)
  mean time:        5.728 μs (8.95% GC)
  maximum time:     4.027 ms (99.73% GC)
  --------------
  samples:          10000
  evals/sample:     7

julia> @benchmark collect(f2($v))
BenchmarkTools.Trial:
  memory estimate:  432 bytes
  allocs estimate:  12
  --------------
  minimum time:     1.962 μs (0.00% GC)
  median time:      2.199 μs (0.00% GC)
  mean time:        2.661 μs (13.79% GC)
  maximum time:     2.885 ms (99.83% GC)
  --------------
  samples:          10000
  evals/sample:     10

julia> v = (a = 1, c = 2)
(a = 1, c = 2)

julia> @benchmark collect(f1($v))
BenchmarkTools.Trial:
  memory estimate:  288 bytes
  allocs estimate:  7
  --------------
  minimum time:     274.668 ns (0.00% GC)
  median time:      282.671 ns (0.00% GC)
  mean time:        318.753 ns (7.93% GC)
  maximum time:     103.501 μs (99.61% GC)
  --------------
  samples:          10000
  evals/sample:     301

julia> @benchmark collect(f2($v))
BenchmarkTools.Trial:
  memory estimate:  416 bytes
  allocs estimate:  11
  --------------
  minimum time:     1.836 μs (0.00% GC)
  median time:      1.919 μs (0.00% GC)
  mean time:        2.077 μs (3.74% GC)
  maximum time:     779.612 μs (99.59% GC)
  --------------
  samples:          10000
  evals/sample:     10
codecov-io commented 5 years ago

Codecov Report

Merging #61 into master will decrease coverage by 1.35%. The diff coverage is 92.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #61      +/-   ##
==========================================
- Coverage   66.66%   65.31%   -1.36%     
==========================================
  Files           1        1              
  Lines         246      222      -24     
==========================================
- Hits          164      145      -19     
+ Misses         82       77       -5
Impacted Files Coverage Δ
src/IterTools.jl 65.31% <92.85%> (-1.36%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update acb368c...6e3619a. Read the comment docs.

iamed2 commented 5 years ago

Please add the docstrings to docs/src/index.md