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

Implement padding #18

Open
lmiq opened this issue Sep 1, 2021 · 0 comments
Open

Implement padding #18

lmiq opened this issue Sep 1, 2021 · 0 comments
Labels
enhancement New feature or request performance

Comments

@lmiq
Copy link
Member

lmiq commented Sep 1, 2021

julia> using StaticArrays, FastPow, BenchmarkTools

julia> function forces!(x,f,d,idxs)
           @inbounds for id in axes(idxs,1)
               i = idxs[id,1]
               j = idxs[id,2]
               r = x[j] - x[i] 
               @fastpow dudr = -12*(1/d^7 - 1/d^4)*r
               f[i] = f[i] + dudr
               f[j] = f[j] - dudr
          end
          return f
       end
forces! (generic function with 1 method)

julia> @benchmark forces!(x,f,d,idxs) setup = ( 
           x = [ rand(SVector{3,Float64}) for _ in 1:1000 ];
           f = [ zeros(SVector{3,Float64}) for _ in 1:1000 ];
           d = rand();
           idxs = rand(1:1000,200,2)
       )
BenchmarkTools.Trial: 10000 samples with 196 evaluations.
 Range (min … max):  468.296 ns …  2.371 μs  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     485.852 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   506.027 ns ± 68.256 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

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

 Memory estimate: 0 bytes, allocs estimate: 0.

julia> @benchmark forces!(x,f,d,idxs) setup = ( 
           x = [ rand(SVector{4,Float64}) for _ in 1:1000 ];
           f = [ zeros(SVector{4,Float64}) for _ in 1:1000 ];
           d = rand();
           idxs = rand(1:1000,200,2)
       )
BenchmarkTools.Trial: 10000 samples with 310 evaluations.
 Range (min … max):  259.797 ns …  1.496 μs  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     296.848 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   313.750 ns ± 55.203 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

     ▆█▇▄▃▁                                                     
  ▁▂████████▇▆▆▅▄▄▃▄▃▃▂▂▂▂▂▂▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂
  260 ns          Histogram: frequency by time          550 ns <

 Memory estimate: 0 bytes, allocs es

@lmiq lmiq added the enhancement New feature or request label Sep 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request performance
Projects
None yet
Development

No branches or pull requests

1 participant