如何绘制基准输出? [英] How can I plot benchmark output?
问题描述
我正在学习 rbenchmark
包以对算法进行基准测试,并查看R环境中的性能.但是,当我增加输入量时,基准结果会彼此不同.为了显示算法对于不同输入的性能,需要生成折线图或曲线.我希望有一条线或曲线显示使用不同数量的输入时的性能差异.我使用的算法工作O(n ^ 2).在结果图中, X
轴显示输入的观察次数, Y
轴分别显示运行时间.我可以通过使用 ggplo2
更优雅地完成此操作?任何人都可以给我一些想法来生成所需的情节吗?有什么想法吗?
I am learning rbenchmark
package to benchmark algorithm and see the performance in R environment. However, when I increased the input, benchmark result are varied one to another. To show how the performance of algorithm for different input, producing line graph or curve is needed. I expect to have one line or curve that show the performance difference of using different number of input. The algorithm I used, works O(n^2) .In resulted plot, X
axis show number of observation of input, Y
axis shows the run time respectively.How can I make this happen more elegantly by using ggplo2
? Can anyone give me some idea to generate desired plot ? Any idea please ?
让我们想象一下,这些是输入文件:
Let's imagine, these are input files :
foo.csv
bar.csv
cat.csv
当我使用两个csv文件作为输入时的基准测试结果:
benchmark result when I used two csv files as an input :
df_2 <- data.frame(
test=c("s3","s7","s4" ,"s1" ,"s2" ,"s5" ,"s6" ,"s9","s8"),
replications=c(10,10, 10, 10 ,10 ,10 ,10 ,10 ,10),
elapsed=c(0.23, 0.28, 0.53 , 0.80 , 4.12 , 8.57 , 8.81 ,20.16 ,24.53),
relative=c( 1.000 , 1.217 , 2.304 , 3.478 , 17.913 , 37.261 , 38.304 , 87.652 ,106.652),
user.self=c(0.23, 0.28 , 0.53 , 0.61 , 4.13 , 8.55 , 8.80 ,18.06 ,19.08),
sys.self=c(0.00, 0.00 ,0.00, 0.00 ,0.00, 0.00 ,0.00 ,0.13, 0.51)
)
这次,我使用了三个csv文件作为输入:
This time I used three csv files as an input :
df_3 <- data.frame(
test=c("s3", "s7" ,"s4", "s1", "s5", "s6","s2", "s9","s8"),
replications=c(10,10, 10, 10 ,10 ,10 ,10 ,10 ,10),
elapsed=c( 0.34 , 0.47 , 0.70 , 2.41 ,8.26 , 8.75 , 9.03, 28.78 ,36.56),
relative=c( 1.000 , 1.382 , 2.059 , 7.088 , 24.294 , 25.735 , 26.559 ,84.647 ,107.529),
user.self=c(0.34 , 0.46 ,0.70 , 1.72 , 8.26 , 8.74 ,9.01, 26.24 ,30.95),
sys.self=c(0.00 ,0.00 ,0.00, 0.12, 0.00 ,0.00 ,0.00, 0.12 ,0.77)
)
在我想要的绘图中,必须将两个折线图或曲线放在一个网格中.
In my desired plot, two line plot or curve must be placed in one grid.
如何使用上述基准测试结果获得漂亮的折线图或曲线?如何获得所需的图,以显示R中算法的性能?非常感谢
How can I get nice line graph or curve by using above benchmark result ? How can I achieve desired plot that show performance of algorithm in R ? Thanks a lot
推荐答案
您可以尝试一下(假设 s1,s2,s3,...
代表不同的测试,可能使用不同的n
,您要比较的结果与 df_3
的结果 df_2
):
You can try this (assuming that s1, s2, s3, ...
represent different tests, possibly with different n
, that you want to compare, with the results df_2
against df_3
):
library(reshape2)
df_2 <- melt(df_2, id='test')
df_3 <- melt(df_3, id='test')
df_2$num_input <- 'two_input'
df_3$num_input <- 'three_input'
df <- rbind(df_2, df_3)
library(ggplot2)
ggplot(df, aes(test, value, group=num_input, col=num_input)) + geom_point() + geom_line() + facet_wrap(~variable)
如果要针对 test
绘制已使用
的图形,请尝试以下操作:
If you want to plot elapsed
against test
try this:
ggplot(df[df$variable=='elapsed',], aes(test, value, group=num_input, col=num_input)) + geom_point() + geom_line(lwd=2) + ylab('elapsed') +
theme(text=element_text(size=15))
如果您想要更具可读性的图像,请尝试以下操作:
If you want more readable images, try this:
ggplot(df, aes(test, value, group=num_input, col=num_input)) + geom_point() + geom_line(lwd=2) + facet_wrap(~variable) +
theme(text=element_text(size=15))
geom_smooth
ggplot(df[df$variable=='elapsed',], aes(test, value, group=num_input, col=num_input)) +
geom_point() + geom_smooth(span=0.7, se=FALSE) + ylab('elapsed') +
theme(text=element_text(size=15))
这篇关于如何绘制基准输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!