Closed primo-ppcg closed 11 months ago
Here are my numbers...
master (a13aeaf9):
$ JANET_PATH=~/src/spork/jpm_tree/lib ~/src/janet/build/janet ~/scratch/mean-partition.janet
partition 1.000s, 27.67µs/body
@[(0 1 2) (3 4 5) (6 7 8) (9 10)]
mean-partition branch (a7536268):
$ JANET_PATH=~/src/spork/jpm_tree/lib ~/src/janet.primo-ppcg/build/janet ~/scratch/mean-partition.janet
partition 1.000s, 24.82µs/body
@[(0 1 2) (3 4 5) (6 7 8) (9 10)]
...and some manual invocations:
$ ~/src/janet.primo-ppcg/build/janet
Janet 1.30.0-a7536268 linux/x64/gcc - '(doc)' for help
repl:1:> (partition 2 (fiber/new (fn [] (each i [:a :b :c :d] (yield i)))))
@[(:a :b) (:c :d)]
repl:2:> (mean (fiber/new (fn [] (each i [2 3 5 7 11] (yield i)))))
5.6
repl:3:> (/ 28 5)
5.6
Your changes escaped the test monster again!
Functions still in my sights:
reduce2
accumulate
accumulate2
kvs
May be there could be some tests for the new ability of mean
and partition
to handle non-lengthable things.
Perhaps something like the following in test/suite-boot.janet
?
# #1283
(assert (deep=
(partition 2 (fiber/new (fn []
(each i [:a :b :c :d] (yield i)))))
'@[(:a :b) (:c :d)]))
(assert (= (mean (fiber/new (fn []
(each i [2 3 5 7 11] (yield i)))))
5.6))
Thanks!
partition
partition
to work with non-lengthable typesmean
to work with non-lengthable types(def a (range 1000)) (timeit-loop [:timeout 1] "partition" (partition 5 a)) (pp (partition 3 (range 11)))
branch:
Comments
I spent some time trying to optimize partition specially for dictionary types, but was unable to find anything more efficient than slicing over
values
.mean
wouldn't necessarily need to be special-cased forlengthable?
, as the generic case is only about 10% slower, but it can be done simply.