library(pdc)
library(tictoc)

The computation of codebooks in pdc up to embedding dimension 7 is implemented in C code for faster execution. Here is a comparison of the gain in speed by switching from the R implementation using sort to the C implementation based on nested ìf blocks. First, the fast computation in C:

N <- 50000
x <- rnorm(N)
tic()
codebook <- pdc::codebook(x, m=7, use.fast = TRUE)
toc()
#> 0.006 sec elapsed

Then, the naive implementation in R:

tic()
codebook <- pdc::codebook(x, m=7, use.fast = FALSE)
toc()
#> 3.087 sec elapsed