cat(as.character(START <- Sys.time()), "\n")
options(digits = 2)
options(hutilscpp.nThread = 10L)
set.seed(1)
library(bench)
library(hutilscpp)
allocate0_except <- hutilscpp:::allocate0_except
haversineDistance <- hutilscpp:::haversineDistance
is_sorted <- hutilscpp:::is_sorted
cat(difftime(Sys.time(), START), "\n")
packageVersion("hutilscpp")
system_time(x1 <- allocate0_except(2^31 - 2, c(1e8, 21e8), c(1L, -1L)))

which_first

system_time(which_first(x1 != 0))
system_time(which_last(x1 != 0))

and3s

system_time(and3s(x1 != 23L, x1 >= 0L, x1 == 0L))
system_time(and3s(x1 != 0L, x1 >= 0L, x1 == 0L))

sum_and3s

system_time(sum_and3s(x1 != 23L, x1 >= 0L, x1 == 0L))
system_time(sum_and3s(x1 != 0L, x1 >= 0L, x1 == 0L))

divisible16

system_time(divisible16(x1))

is_constant

system_time(is_constant(x1))

is_sorted

system_time(is_sorted(x1))

minmax

system_time(minmax(x1))

Haversine

haversineDistance

y <- runif(1e6, -39, -38)
x <- runif(1e6, 144, 146)
yy <- runif(100, -39, -38)
xx <- runif(100, 144, 145)
system_time(haversineDistance(y, x, y, x))

match_nrst_haversine

system_time(match_nrst_haversine(y, x, yy, xx))
cat(as.character(END <- Sys.time()), "\n")
print(difftime(END, START))
# double
x1 <- as.double(x1)
system_time(which_first(x1 != 0))
bench::system_time(and3s(x1 > 1, x1 == 0))
bench::system_time(and3s(x1 > 1, x1 == 0, x1 %in% yy))


HughParsonage/hutilscpp documentation built on March 1, 2025, 12:29 p.m.