Skip to content

Instantly share code, notes, and snippets.

@RyanGreenup
Created July 9, 2021 11:39
Show Gist options
  • Save RyanGreenup/99bc1ad4ba9e8f267d652ec3ddc49f9e to your computer and use it in GitHub Desktop.
Save RyanGreenup/99bc1ad4ba9e8f267d652ec3ddc49f9e to your computer and use it in GitHub Desktop.
library(ggplot2)
# Enter the data in such a way to match the Plot
data <-
rbind(
c("C", 0.97, 1135),
c("C++", 0.84, 3542),
c("Go", 3.75, 894),
c("Rust", 0.93, 763),
c("Julia", 1.32, 624),
c("Python", 163, 688),
c("Lua", 113, 623),
c("Swift", 1.4, 1165),
c("Intel Fortran", 1.42, 957),
c("Haskell GHC", 1.51, 1975),
c("C#", 3.14, 1974),
c("Chapel", 3.34, 588),
c("F#", 3.77, 897),
c("Pascal", 3.86, 950),
c("Ada", 4.02, 577),
c("Node JS", 4.03, 1122),
c("LISP", 4.09, 2447),
c("Java", 4.15, 796),
c("OCaml", 7.53, 717),
c("Dart", 8.72, 957),
c("Racket", 10.45, 801),
c("PHP", 24.89, 875),
c("Erlang", 44, 792),
c("Ruby", 262, 880)
)
data <- apply(data, 2, rev)
data <- as.data.frame(data)
data[, 2] <- as.numeric(data[, 2])
data[, 2] <- log(data[, 2] + 1)
# Make a Data Frame
df <- as.data.frame(data)
names(df) <- c("Language", "Time", "Characters")
df$Language <- factor(seq_len(nrow(df)), labels = df$Language)
df$Time <- as.numeric(df$Time)
df$Characters <- as.numeric(df$Characters)
# If you want it ordered in descending uncomment below
# df[rank(df$Time), ]
# Make sure the languages keep the order they were given in
# I want them in a specific order
df$Language <- factor(sort(df$Time), labels = df$Language)
factor(df$Language, ordered = TRUE, levels = rank(df$Time))
# Identify clusters with heirarchical clustering
times <- df$Time
names(times) <- df$Language
hc.av <- hclust(dist(times), method = "average")
svg(filename = "/tmp/Dendrogram_of_Language_Performance.svg")
plot(hc.av)
dev.off()
df$Category <- factor(cutree(tree = hc.av, k = 4))
levels(df$Category) <- rev(levels(df$Category))
# Build the Plot
p <- ggplot(df, aes(x = Language, y = Time, fill = Category)) +
geom_col(col = 'black') +
labs(y = "Log Time",
title = "Comparison of Programming Language",
subtitle = "Log Time to Produce 16000 Mandelbrot") +
guides(fill = guide_legend("Performance\nCategory")) +
theme_classic() +
theme(axis.text.x = element_text(
angle = 90,
vjust = 0.5,
hjust = 1
)) +
coord_flip()
ggsave("/tmp/barplot_language_performance_comparison.svg")
p
# Compare Complexity
# df$Time <- exp(df$Time)
df$Characters <- log(df$Characters)
p <- ggplot(df, aes(x = Time, y = Characters, fill = Category)) +
geom_label(aes(label = Language)) +
labs(
y = "Code Length (Log Gzipped bytes)",
x = "Log Time",
title = "Comparison of Programming Language Complexity and Performance",
subtitle = "Log Time to Produce 16000² Mandelbrot"
) +
guides(fill = guide_legend(title = "Performance\nCategory",
override.aes = aes(label = ""))) + # https://stackoverflow.com/a/60730234
theme_classic()
p
ggsave("/tmp/barplot_language_performance_comparison.svg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment