Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More performance #344

Merged
merged 4 commits into from
Nov 12, 2023
Merged

More performance #344

merged 4 commits into from
Nov 12, 2023

Conversation

hyrodium
Copy link
Owner

@hyrodium hyrodium commented Nov 12, 2023

This PR fixes #333

Before this PR

julia> using BasicBSpline, BenchmarkTools

julia> Pd1 = BSplineSpace{2}(knotvector" 21 3")
BSplineSpace{2, Int64, KnotVector{Int64}}(KnotVector([2, 2, 3, 5, 5, 5]))

julia> Pd2 = BSplineSpace{3}(knotvector"212 4")
BSplineSpace{3, Int64, KnotVector{Int64}}(KnotVector([1, 1, 2, 3, 3, 5, 5, 5, 5]))

julia> @benchmark BasicBSpline.changebasis_I(Pd1, Pd2)
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
 Range (min  max):  52.760 μs    3.479 ms  ┊ GC (min  max):  0.00%  95.56%
 Time  (median):     57.709 μs               ┊ GC (median):     0.00%
 Time  (mean ± σ):   65.825 μs ± 149.739 μs  ┊ GC (mean ± σ):  10.40% ±  4.48%

    ▁▃▅▆▇████▇▆▅▄▃▂▂▂▁▁▁▁▁▁ ▁                                  ▃
  ▅▆█████████████████████████▇██▇▇▇▇▅▆▆▆▆▅▆▄▅▄▇▇▇▇▇▅▆▇▄▆▅▆▅▆▆▆ █
  52.8 μs       Histogram: log(frequency) by time      84.5 μs <

 Memory estimate: 98.53 KiB, allocs estimate: 1285.

After this PR

julia> using BasicBSpline, BenchmarkTools

julia> Pd1 = BSplineSpace{2}(knotvector" 21 3")
BSplineSpace{2, Int64, KnotVector{Int64}}(KnotVector([2, 2, 3, 5, 5, 5]))

julia> Pd2 = BSplineSpace{3}(knotvector"212 4")
BSplineSpace{3, Int64, KnotVector{Int64}}(KnotVector([1, 1, 2, 3, 3, 5, 5, 5, 5]))

julia> @benchmark BasicBSpline.changebasis_I(Pd1, Pd2)
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
 Range (min  max):  11.662 μs   3.282 ms  ┊ GC (min  max): 0.00%  97.70%
 Time  (median):     12.975 μs              ┊ GC (median):    0.00%
 Time  (mean ± σ):   15.312 μs ± 64.766 μs  ┊ GC (mean ± σ):  8.26% ±  1.94%

     ▇██▃▁                                                     
  ▂▄██████▅▄▃▂▂▃▃▄▃▃▃▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂
  11.7 μs         Histogram: frequency by time        23.8 μs <

 Memory estimate: 20.44 KiB, allocs estimate: 285.

Copy link

codecov bot commented Nov 12, 2023

Codecov Report

Merging #344 (47046aa) into main (db826f7) will decrease coverage by 0.14%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #344      +/-   ##
==========================================
- Coverage   96.56%   96.43%   -0.14%     
==========================================
  Files          14       14              
  Lines        1574     1571       -3     
==========================================
- Hits         1520     1515       -5     
- Misses         54       56       +2     
Files Coverage Δ
src/_BSplineSpace.jl 93.78% <100.00%> (-0.07%) ⬇️
src/_ChangeBasis.jl 94.07% <100.00%> (-0.02%) ⬇️

... and 1 file with indirect coverage changes

@hyrodium
Copy link
Owner Author

Before this PR

julia> using BasicBSpline, BenchmarkTools

julia> P6 = BSplineSpace{2}(knotvector"1111 111")
BSplineSpace{2, Int64, KnotVector{Int64}}(KnotVector([1, 2, 3, 4, 6, 7, 8]))

julia> P7 = BSplineSpace{2}(knotvector"11121111")
BSplineSpace{2, Int64, KnotVector{Int64}}(KnotVector([1, 2, 3, 4, 4, 5, 6, 7, 8]))

julia> P6  P7
true

julia> P6  P7
true

julia> @benchmark P6  P7
BenchmarkTools.Trial: 10000 samples with 996 evaluations.
 Range (min  max):  23.789 ns  53.344 ns  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     24.173 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   24.400 ns ±  1.360 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

   █▇▅▃▂▁                                                     ▂
  ███████▅▅▄▃▁▄▅▄▅▅▅▇▆▆▇▅▆▃▅▅▄▃▄▄▁▁▁▁▃▁▁▃▁▃▃▁▁▁▁▁▁▁▁▁▁▁▁▁▃▁▁▅ █
  23.8 ns      Histogram: log(frequency) by time      35.5 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

julia> @benchmark P6  P7
BenchmarkTools.Trial: 10000 samples with 301 evaluations.
 Range (min  max):  291.714 ns   12.953 μs  ┊ GC (min  max):  0.00%  95.71%
 Time  (median):     316.198 ns               ┊ GC (median):     0.00%
 Time  (mean ± σ):   379.197 ns ± 800.701 ns  ┊ GC (mean ± σ):  14.42% ±  6.62%

      ▁▄▇█▇▄                                                     
  ▁▂▃▆███████▅▃▂▂▂▂▂▂▁▁▁▁▂▂▂▃▃▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂
  292 ns           Histogram: frequency by time          478 ns <

 Memory estimate: 752 bytes, allocs estimate: 9.

After this PR

julia> using BasicBSpline, BenchmarkTools

julia> P6 = BSplineSpace{2}(knotvector"1111 111")
BSplineSpace{2, Int64, KnotVector{Int64}}(KnotVector([1, 2, 3, 4, 6, 7, 8]))

julia> P7 = BSplineSpace{2}(knotvector"11121111")
BSplineSpace{2, Int64, KnotVector{Int64}}(KnotVector([1, 2, 3, 4, 4, 5, 6, 7, 8]))

julia> P6  P7
true

julia> P6  P7
true

julia> @benchmark P6  P7
BenchmarkTools.Trial: 10000 samples with 996 evaluations.
 Range (min  max):  23.126 ns  47.963 ns  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     23.660 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   24.191 ns ±  2.216 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  ▄▆█▇▃▂▂                                                  ▂  ▂
  ███████▇▆█▆▅▅▆▇▇▇▇▇▆▇▆▆▆▆▆▅▃▄▄▃▅▁▃▄▁▄▃▅▄▁▃▃▃▃▁▁▃▁▁▃▄▁▄██▅█▇ █
  23.1 ns      Histogram: log(frequency) by time      35.1 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

julia> @benchmark P6  P7
BenchmarkTools.Trial: 10000 samples with 996 evaluations.
 Range (min  max):  23.187 ns  41.766 ns  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     23.670 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   24.101 ns ±  1.958 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  ▃▇██▃▁                                                  ▂▁▁ ▂
  ██████▅▅▄▅▅▅▅▆▆▆▇▇█▆▇▆▆▇▅▆▅▆▅▅▄▅▁▃▃▁▁▃▄▃▄▃▁▄▁▁▁▄▄▃▄▆▇▇█████ █
  23.2 ns      Histogram: log(frequency) by time      33.1 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

@hyrodium
Copy link
Owner Author

#323 (comment)

Still can be improved, but getting better.

Before this PR

julia> using BasicBSpline, BenchmarkTools

julia> p = 3
3

julia> P = BSplineSpace{p}(KnotVector(1:10))
BSplineSpace{3, Int64, KnotVector{Int64}}(KnotVector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))

julia> P′ = BSplineSpace{p}(KnotVector([1,2,3,4,4.5,5,6,7,8.1,9.1,10.5]))
BSplineSpace{3, Float64, KnotVector{Float64}}(KnotVector([1.0, 2.0, 3.0, 4.0, 4.5, 5.0, 6.0, 7.0, 8.1, 9.1, 10.5]))

julia> changebasis(P,P′)
6×7 SparseArrays.SparseMatrixCSC{Float64, Int32} with 13 stored entries:
 1.0  0.166667                                 
     0.833333  0.5                             
              0.5  0.833333                    
                  0.166667  1.0  -0.0333333   0.0183333
                                1.03333    -0.103333
                                           1.085

julia> @benchmark changebasis(P,P′)
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
 Range (min  max):  214.406 μs    3.984 ms  ┊ GC (min  max):  0.00%  92.05%
 Time  (median):     222.922 μs               ┊ GC (median):     0.00%
 Time  (mean ± σ):   254.091 μs ± 320.269 μs  ┊ GC (mean ± σ):  11.10% ±  8.23%

   ▁▃▅▇██▇▆▄▃▃▃▃▂▂▂▁                                            ▂
  ▅███████████████████▇▇▆▇▇▅▅▆▆▆▇▄▆▆▆▆▅▆▄▆▅▅▆▃▃▂▂▄▃▄▅▄▅▅▆▅▆▆▅▅▅ █
  214 μs        Histogram: log(frequency) by time        295 μs <

 Memory estimate: 363.89 KiB, allocs estimate: 4150.

After this PR

julia> using BasicBSpline, BenchmarkTools

julia> p = 3
3

julia> P = BSplineSpace{p}(KnotVector(1:10))
BSplineSpace{3, Int64, KnotVector{Int64}}(KnotVector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))

julia> P′ = BSplineSpace{p}(KnotVector([1,2,3,4,4.5,5,6,7,8.1,9.1,10.5]))
BSplineSpace{3, Float64, KnotVector{Float64}}(KnotVector([1.0, 2.0, 3.0, 4.0, 4.5, 5.0, 6.0, 7.0, 8.1, 9.1, 10.5]))

julia> changebasis(P,P′)
6×7 SparseArrays.SparseMatrixCSC{Float64, Int32} with 13 stored entries:
 1.0  0.166667                                 
     0.833333  0.5                             
              0.5  0.833333                    
                  0.166667  1.0  -0.0333333   0.0183333
                                1.03333    -0.103333
                                           1.085

julia> @benchmark changebasis(P,P′)
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
 Range (min  max):  26.300 μs    4.336 ms  ┊ GC (min  max):  0.00%  97.00%
 Time  (median):     28.945 μs               ┊ GC (median):     0.00%
 Time  (mean ± σ):   34.048 μs ± 118.740 μs  ┊ GC (mean ± σ):  10.23% ±  2.92%

      ▄██▅▃                                                     
  ▁▂▃▇█████▇▅▃▂▂▂▂▄▅▆▆▅▄▃▃▂▂▂▂▂▂▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂
  26.3 μs         Histogram: frequency by time         45.3 μs <

 Memory estimate: 40.86 KiB, allocs estimate: 508.

@hyrodium hyrodium merged commit a649f92 into main Nov 12, 2023
12 of 13 checks passed
@hyrodium hyrodium deleted the feature/more_performance branch November 12, 2023 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

issqsubset can be faser
1 participant