-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo8.R
44 lines (28 loc) · 1.13 KB
/
demo8.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
# ---- DEMO 8 ----
# Performance testing
# ---- 8.1 Scaling with input size -----
library(ggplot2)
time <- numeric()
# timing
time[1] <- unlist(system.time(getLargestPrimeFactor(600851475143))[3])
# timing - 10x bigger
time[2] <- unlist(system.time(getLargestPrimeFactor(6008514751430))[3])
# timing - 100x bigger
time[3] <- unlist(system.time(getLargestPrimeFactor(60085147514300))[3])
# timing - 1000x bigger
time[4] <- unlist(system.time(getLargestPrimeFactor(600851475143000))[3])
# timing - 5000x bigger
time[5] <- unlist(system.time(getLargestPrimeFactor(600851475143000*5))[3])
# timing - 10000x bigger
time[6] <- unlist(system.time(getLargestPrimeFactor(6008514751430000))[3])
# timing - 100000x bigger - too slow...
#time[[7]] <- system.time(getLargestPrimeFactor(60085147514300000))[3]
size <- c(1,10,100,1000,5000,10000)
dfPerfData <- data.frame(size,time)
names(dfPerfData) <- c('Relative_Size', 'Run_time')
plt <- ggplot(data = dfPerfData, aes(x = Relative_Size, y = Run_time))
plt <- plt + geom_line() + geom_point()
plt
# ---- 8.2 Profiling with profvis -----
library(profvis)
profvis(getLargestPrimeFactor(600851475143000))