Skip to content

Commit 0604714

Browse files
committed
update NEWS
1 parent 2dfb740 commit 0604714

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

NEWS.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -293,20 +293,22 @@
293293

294294
41. `tables()` is faster by default by excluding the size of character strings in R's global cache (which may be shared) and excluding the size of list column items (which also may be shared). `mb=` now accepts any function which accepts a `data.table` and returns a higher and better estimate of its size in bytes, albeit more slowly; e.g. `mb = utils::object.size`.
295295
296-
27. New function `topn(x,n)` [#3804](https://github.com/Rdatatable/data.table/issues/3804). It returns the indices of the `n` smallest/largest values of a vector `x`. Previously, one had to use `order(x)[1:n]` which produced a full sorting of `x`. Usage of `topn` is advised for large vectors where sorting takes long time. Thanks to Michael Chirico for requesting, and Benjamin Schwendinger for PR.
296+
27. New function `topn(x,n)` [#3804](https://github.com/Rdatatable/data.table/issues/3804). It returns the indices of the `n` smallest/largest values of a vector `x`. Previously, one had to use `order(x)[1:n]` which produced a full sorting of `x`. Usage of `topn` is advised for large vectors where sorting takes long time. Thanks to Michael Chirico for requesting, and Benjamin Schwendinger for the PR.
297297
298298
```R
299299
set.seed(123)
300300
x = rnorm(1e8)
301-
system.time(topn(x, 5L,sorted=TRUE))
302-
# user system elapsed
303-
# 0.287 0.000 0.288
304-
system.time(topn(x, 5L,sorted=FALSE))
305-
# user system elapsed
306-
# 0.283 0.000 0.282
307-
system.time(order(x)[1L:5L])
308-
# user system elapsed
309-
# 6.658 0.620 7.279
301+
bm = bench::mark(check=FALSE, min_iterations=10,
302+
topn(x, 5L, sorted=TRUE),
303+
topn(x, 5L, sorted=FALSE),
304+
order(x)[1:5]
305+
)
306+
setDT(bm)[, .(expression, min, median, lapply(time, max), mem_alloc)]
307+
# expression min median V4 mem_alloc
308+
# <bench_expr> <bench_time> <bench_time> <list> <bench_bytes>
309+
# 1: topn(x, 5L, sorted = TRUE) 151.65ms 155.21ms 171ms 0B
310+
# 2: topn(x, 5L, sorted = FALSE) 151.59ms 158.77ms 176ms 0B
311+
# 3: order(x)[1:5] 2.69s 2.77s 2.84s 381MB
310312
```
311313
312314
## BUG FIXES

0 commit comments

Comments
 (0)