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

Owl.Dense.Ndarray.S.copy_ is 3-4x slower than Owl_base_dense_ndarray_generic.copy_ #685

Open
nathanfarlow opened this issue Dec 1, 2024 · 0 comments

Comments

@nathanfarlow
Copy link

Hello,
Owl.Dense.Ndarray.S.copy_ is ~3-4x slower than Owl_base_dense_ndarray_generic.copy_ because it doesn't call Genarray.blit. Is this intentional/necessary? Can Owl_dense_ndarray_generic.copy_ be updated to use Owl_base_dense_ndarray_generic.copy_? Below are some benchmarks:

open Core
open Core_bench

let sizes = [ 10; 100; 1000; 10000; 100000; 1000000; 10000000 ]

let make_bench size =
  let name = Printf.sprintf "Copy 1D array of size %d" size in
  let src = Owl.Dense.Ndarray.S.empty [| size |] in
  let dst = Owl.Dense.Ndarray.S.empty [| size |] in
  Bench.Test.create ~name (fun () -> Owl.Dense.Ndarray.S.copy_ src ~out:dst)
;;

let () =
  let tests = List.map sizes ~f:make_bench in
  Command_unix.run (Bench.make_command tests)
;;
Owl_dense_ndarray_generic.copy_
┌────────────────────────────────┬────────────────┬─────────┬────────────┐
│ Name                           │       Time/Run │ mWd/Run │ Percentage │
├────────────────────────────────┼────────────────┼─────────┼────────────┤
│ Copy 1D array of size 10       │       103.61ns │   4.00w │            │
│ Copy 1D array of size 100      │       114.55ns │   4.00w │            │
│ Copy 1D array of size 1000     │       291.18ns │   4.00w │      0.01% │
│ Copy 1D array of size 10000    │     2_006.74ns │   4.00w │      0.09% │
│ Copy 1D array of size 100000   │    18_705.19ns │   4.00w │      0.80% │
│ Copy 1D array of size 1000000  │   185_585.75ns │   4.00w │      7.97% │
│ Copy 1D array of size 10000000 │ 2_327_796.01ns │   4.00w │    100.00% │
└────────────────────────────────┴────────────────┴─────────┴────────────┘
Owl_base_dense_ndarray_generic.copy_
┌────────────────────────────────┬──────────────┬─────────┬────────────┐
│ Name                           │     Time/Run │ mWd/Run │ Percentage │
├────────────────────────────────┼──────────────┼─────────┼────────────┤
│ Copy 1D array of size 10       │      94.01ns │  36.00w │      0.02% │
│ Copy 1D array of size 100      │      97.32ns │  36.00w │      0.02% │
│ Copy 1D array of size 1000     │     115.62ns │  36.00w │      0.02% │
│ Copy 1D array of size 10000    │     639.84ns │  36.00w │      0.11% │
│ Copy 1D array of size 100000   │   5_578.15ns │  36.00w │      0.95% │
│ Copy 1D array of size 1000000  │  61_613.86ns │  36.00w │     10.49% │
│ Copy 1D array of size 10000000 │ 587_095.10ns │  36.00w │    100.00% │
└────────────────────────────────┴──────────────┴─────────┴────────────┘

image

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

No branches or pull requests

1 participant