-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpolars.R
61 lines (61 loc) · 1.73 KB
/
polars.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
library(polars)
set.seed(108)
# mean
test1 = function(N, W) {
for (n in N) {
x = pl$DataFrame(list(V1=rnorm(n)))
for (w in W) {
t = system.time(
ans <- x$select(pl$col("V1")$rolling_mean(window_size=w))
)[["elapsed"]]
cat("polars,mean,single,",n,",",w,",",t,"\n",sep="")
}
}
}
test4 = function(N, W) {
for (n in N) {
x = pl$DataFrame(setNames(replicate(2L, rnorm(n), simplify=FALSE), c("V1","V2")))
for (w in W) {
ww = w + c(-10L,10L)
t = system.time(
ans <- list(
x$select(pl$col(c("V1","V2"))$rolling_mean(window_size=ww[1])),
x$select(pl$col(c("V1","V2"))$rolling_mean(window_size=ww[2]))
)
)[["elapsed"]]
cat("polars,mean,quadruple,",n,",",w,",",t,"\n",sep="")
}
}
}
test1(N = c(1e6, 1e7, 1e8), W = c(1e2, 1e3, 1e4))
test4(N = c(1e6, 1e7, 1e8), W = c(1e2, 1e3, 1e4))
# median
test1 = function(N, W) {
for (n in N) {
df = pl$DataFrame(list(V1=rnorm(n)))
for (w in W) {
t = system.time(
ans <- df$select(pl$col("V1")$rolling_median(window_size=w))
)[["elapsed"]]
cat("polars,median,single,",n,",",w,",",t,"\n",sep="")
}
}
}
test4 = function(N, W) {
for (n in N) {
x = pl$DataFrame(setNames(replicate(2L, rnorm(n), simplify=FALSE), c("V1","V2")))
for (w in W) {
ww = w + c(-10L,10L)
t = system.time(
ans <- list(
x$select(pl$col(c("V1","V2"))$rolling_median(window_size=ww[1])),
x$select(pl$col(c("V1","V2"))$rolling_median(window_size=ww[2]))
)
)[["elapsed"]]
cat("polars,median,quadruple,",n,",",w,",",t,"\n",sep="")
}
}
}
test1(N = c(1e6, 1e7, 1e8), W = c(1e2, 1e3, 1e4))
test4(N = c(1e6, 1e7, 1e8), W = c(1e2, 1e3, 1e4))
q(status=0)