Skip to content

Commit

Permalink
Fix benchmark postprocess and plot script
Browse files Browse the repository at this point in the history
  • Loading branch information
viercc committed Dec 14, 2024
1 parent 465ec34 commit c8efcd5
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 157 deletions.
34 changes: 21 additions & 13 deletions bench/analyze.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@ library(ggplot2)
srcfile <- 'benchdata/bench_preprocessed.csv'

data <- read.csv(srcfile)
pico = 1E-12
data$Mean <- data$Mean * pico
data$StdDev <- data$SDx2 * 0.5 * pico
data$MeanLB <- pmax(pico, data$Mean - data$StdDev)
data$MeanUB <- data$Mean + data$StdDev

plotComparison <- function(data, filename) {
plt <- ggplot(data) +
aes(x=Method, y=MeanTime, ymin=MeanLB, ymax=MeanUB, color=Name) +
aes(
x=Method,
y=Mean,
ymin=MeanLB,
ymax=MeanUB,
color=Name) +
scale_y_log10(breaks=10^(0:-8)) +
geom_errorbar(width=0.5) +
geom_point()
Expand All @@ -17,11 +27,11 @@ plotRatio <- function(data, target_name, base_name, filename) {
data_baseline <- subset(data, Name == base_name)
data_target <- subset(data, Name == target_name)
ratio_data <- data.frame(data_target)
ratio_data$MeanTime <- ratio_data$MeanTime / data_baseline$MeanTime
ratio_data$Mean <- ratio_data$Mean / data_baseline$Mean
ratio_data$MeanLB <- ratio_data$MeanLB / data_baseline$MeanUB
ratio_data$MeanUB <- ratio_data$MeanUB / data_baseline$MeanLB
plt <- ggplot(ratio_data) +
aes(x=Method, y=MeanTime, ymin=MeanLB, ymax=MeanUB) +
aes(x=Method, y=Mean, ymin=MeanLB, ymax=MeanUB) +
scale_y_log10(limits=c(0.001,1000), breaks=10^(-2:2)) +
geom_hline(linewidth=1, color=alpha('red', .6), yintercept=1) +
xlab("") +
Expand All @@ -32,16 +42,14 @@ plotRatio <- function(data, target_name, base_name, filename) {
ggsave(file=filename, plot=plt, dpi=100, width=14, height=8)
}

data$Method <- with(data, reorder(Method, MeanTime))

# isEnglish <- data$Dataset=='English'
# isWiki <- data$Dataset=='Wiki'
# onSetOps <- data$Name=='Set' | data$Name=='TSet'
# onMapOps <- data$Name=='Map' | data$Name=='TMap'
# plotComparison(data[isEnglish & onSetOps,], "benchdata/set-english.png")
# plotComparison(data[isEnglish & onMapOps,], "benchdata/map-english.png")
# plotComparison(data[isWiki & onSetOps,], "benchdata/set-wiki.png")
# plotComparison(data[isWiki & onMapOps,], "benchdata/map-wiki.png")
isEnglish <- data$Dataset=='English'
isWiki <- data$Dataset=='Wiki'
onSetOps <- data$Name=='Set' | data$Name=='TSet'
onMapOps <- data$Name=='Map' | data$Name=='TMap'
plotComparison(data[isEnglish & onSetOps,], "benchdata/set-english.png")
plotComparison(data[isEnglish & onMapOps,], "benchdata/map-english.png")
plotComparison(data[isWiki & onSetOps,], "benchdata/set-wiki.png")
plotComparison(data[isWiki & onMapOps,], "benchdata/map-wiki.png")

plotRatio(subset(data, Method != 'stringCount'), 'TSet', 'Set', "benchdata/ratio-set.png")
plotRatio(subset(data, Method != 'stringCount'), 'TMap', 'Map', "benchdata/ratio-map.png")
2 changes: 1 addition & 1 deletion doc/benchmark-generation-date
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-06-08T00:44:16+09:00
2024-12-14T13:53:16+09:00
282 changes: 141 additions & 141 deletions doc/benchmark.csv

Large diffs are not rendered by default.

Binary file added doc/map-english.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/map-wiki.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/ratio-map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/ratio-set.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/set-english.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/set-wiki.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions run_bench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ fi
# Run benchmark
datestr="$(date -Iseconds)"
benchfile="benchdata/bench-${datestr}.csv"
cabal run trie-benchmark -- -s "--csv=$benchfile"
cabal run trie-benchmark -- "--csv=$benchfile"
# Preprocess the output file
sed -e 's/Name,Mean/Dataset\/Name\/Category\/Method,MeanTime/' "$benchfile" | tr '/' ',' > ./benchdata/bench_preprocessed.csv
sed \
-e '1c Dataset,Name,Method,Mean,SDx2' \
-e 's/^All\.\([[:alnum:]]*\)\.\([[:alnum:]]*\)\.\([[:alnum:]]*\)\.\([[:alnum:]]*\)/\1,\2,"\3.\4"/g' \
"$benchfile" \
> ./benchdata/bench_preprocessed.csv
# Draw charts using R
R CMD BATCH bench/analyze.R

Expand Down

0 comments on commit c8efcd5

Please sign in to comment.