Parallel Sort
psort.RdSimilar to base::sort, but only for character vectors and partly
using parallelism. It is experimental and might change in the future.
Use with caution.
Usage
psort(x, decreasing=FALSE, na.last=NA,
nThread=getOption("kit.nThread"),c.locale=TRUE)Arguments
- x
A character vector. For other input,
psort()warns and callsbase::sort().- na.last
Controls the treatment of
NAs. IfTRUE, missing values are put last; ifFALSE, they are put first; ifNA, they are removed.- decreasing
Logical. If
TRUE, sort in decreasing order. Default isFALSE.- nThread
Integer. Number of threads to use. Default is
getOption("kit.nThread").- c.locale
Logical. If
TRUE(default), sort byte by byte in the C locale. The result is the same on every operating system and matchessort(x, method = "radix"). IfFALSE, use the session locale andsort(x, method = "quick"); the order of accented letters and other non-ASCII text can differ between operating systems and locales.
Details
For non-character x, psort() warns and calls
base::sort() with method = "radix" when
c.locale = TRUE, and method = "quick" otherwise.
Examples
x = c("b","A","B","a","\xe4")
Encoding(x) = "latin1"
identical(psort(x, c.locale=FALSE), sort(x))
#> [1] TRUE
identical(psort(x, c.locale=TRUE), sort(x, method="radix"))
#> [1] TRUE
# Benchmarks
# ----------
# strings = as.character(as.hexmode(1:1000))
# x = sample(strings, 1e8, replace=TRUE)
# system.time({kit::psort(x, na.last = TRUE, nThread = 1L)})
# user system elapsed
# 2.833 0.434 3.277
# system.time({sort(x,method="radix",na.last = TRUE)})
# user system elapsed
# 5.597 0.559 6.176
# system.time({x[order(x,method="radix",na.last = TRUE)]})
# user system elapsed
# 5.561 0.563 6.143