Skip to content

Instantly share code, notes, and snippets.

@twittoru
Created November 12, 2011 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twittoru/1360188 to your computer and use it in GitHub Desktop.
Save twittoru/1360188 to your computer and use it in GitHub Desktop.
Tsukuba.R#9 appendix2
library(ggplot2)
# inline でのプロット 省略の波は Keynote のテキストをはっつけた
inline <- data.frame(x=c("C", "RCpp", "Pure R"), y=c(0.219, 0.242, 27.969))
ggplot(inline, aes(x=x, y=y))
+ geom_bar(aes(fill=x)) # x ごとに色づけ
+ coord_cartesian(ylim=c(0, 0.5)) # y 軸を制限 (はみでる barplot は scale_y_continuous で制限はできない)
+ scale_y_continuous(name="elapsed",
breaks=c(0, 0.1, 0.2, 0.3, 0.4, 0.5), # 適当に軸を分割する
labels=c(0, 0.1, 0.2, 26, 27, 28)) # フリーダムにラベルを張る
+ theme_grey(base_size=16) # ちょっとフォントサイズを大きくする
ggsave("inline.pdf") # 保存する
# inline でのコード行数比較
codeline <- data.frame(x=c("inline", "outside"), y=c(16, 22))
ggplot(codeline, aes(x=x, y=y))
+ geom_bar()
+ scale_y_continuous(name="line of code")
+ coord_cartesian(ylim=c(10, 22))
ggsave("codeline.pdf")
# compiler でのプロット
compiler <- data.frame(x=c("C", "RCpp", "Pure R", "Compiler"),
y=c(0.219, 0.242, 27.969, 10.604))
ggplot(compiler, aes(x=x, y=y))
+ geom_bar(aes(fill=x))
+ scale_y_continuous(name="elapsed", breaks=1000*(1:9))
+ theme_grey(base_size=16)
+ coord_cartesian(ylim=c(0, 10000))
ggsave("compiler.pdf")
# revolution での プロット
# legend が重なるように Keynote で重ねたのであって、ggplot2 の facet を使っているわけではない
desc <- "
ベンチマーク結果を以下のように整形する 僕は Vim で頑張った
ファイルはこの gist に張ってある
<== Test period ==> : <== Method name (trimmed "-* (sec)") ==> : <== score time ==>
"
benches <- lapply(c("r-bare.txt", "revo1core.txt", "revo2core.txt"),
function (file) read.csv(file, sep=":", header=F))
ggplot(benches[[1]], aes(x=V1, y=V3)) # bare r の結果が入ってる
+ geom_bar(aes(fill=V2)) # テストケースごとに色わけ
+ scale_x_discrete(name=""
labels=c("I", "II", "III", "TOTAL"), # ラベルを振る
breaks=levels(benches[[1]]$V1)) # discreate なので breaks は levels
+ scale_y_continuous(name="sec")
+ theme_grey(base_size=12)
ggsave("bare-R.pdf")
ggplot(benches[[2]], aes(x=V1, y=V3)) # revolution 1-core の結果が入ってる
+ geom_bar(aes(fill=V2))
+ scale_x_discrete(name=""
labels=c("I", "II", "III", "TOTAL"),
breaks=levels(benches[[2]]$V1))
+ scale_y_continuous(name="sec")
+ theme_grey(base_size=12)
ggsave("revo1core.pdf")
ggplot(benches[[3]], aes(x=V1, y=V3)) # revolution 2-core の結果が入ってる
+ geom_bar(aes(fill=V2))
+ scale_x_discrete(name=""
labels=c("I", "II", "III", "TOTAL"),
breaks=levels(benches[[3]]$V1))
+ scale_y_continuous(name="sec")
+ theme_grey(base_size=12)
ggsave("revo2core.pdf")
I. Matrix calculation:Creation, transp., deformation of a 2500x2500 matrix: 1.49133333333333
I. Matrix calculation:2400x2400 normal distributed random matrix ^1000: 0.720333333333333
I. Matrix calculation:Sorting of 7,000,000 random values: 1.13333333333333
I. Matrix calculation:2800x2800 cross-product matrix (b = a' * a): 19.3946666666667
I. Matrix calculation:Linear regr. over a 3000x3000 matrix (c = a \ b'): 8.623
II. Matrix functions:FFT over 2,400,000 random values: 0.816333333333333
II. Matrix functions:Eigenvalues of a 640x640 random matrix: 1.31733333333333
II. Matrix functions:Determinant of a 2500x2500 random matrix: 5.24366666666667
II. Matrix functions:Cholesky decomposition of a 3000x3000 matrix: 6.48833333333333
II. Matrix functions:Inverse of a 1600x1600 random matrix: 5.32899999999999
III. Programmation:3,500,000 Fibonacci numbers calculation (vector calc)(sec): 1.17899999999999
III. Programmation:Creation of a 3000x3000 Hilbert matrix (matrix calc): 0.735666666666665
III. Programmation:Grand common divisors of 400,000 pairs (recursion): 3.47299999999998
III. Programmation:Creation of a 500x500 Toeplitz matrix (loops): 1.34400000000001
III. Programmation:Escoufier's method on a 45x45 matrix (mixed): 0.951999999999998
TOTAL:Total time for all 15 tests: 58.241
TOTAL:Overall mean (sum of I, II and III trimmed means/3): 2.10437988311317
I. Matrix calculation:Creation, transp., deformation of a 2500x2500 matrix: 4.56066666666667
I. Matrix calculation:2400x2400 normal distributed random matrix ^1000: 0.707333333333333
I. Matrix calculation:Sorting of 7,000,000 random values: 1.09066666666667
I. Matrix calculation:2800x2800 cross-product matrix (b = a' * a): 3.93266666666667
I. Matrix calculation:Linear regr. over a 3000x3000 matrix (c = a \ b'): 1.97433333333333
II. Matrix functions:FFT over 2,400,000 random values: 0.791333333333332
II. Matrix functions:Eigenvalues of a 640x640 random matrix: 0.786666666666667
II. Matrix functions:Determinant of a 2500x2500 random matrix: 1.78866666666666
II. Matrix functions:Cholesky decomposition of a 3000x3000 matrix: 1.69266666666666
II. Matrix functions:Inverse of a 1600x1600 random matrix: 1.50366666666667
III. Programmation:3,500,000 Fibonacci numbers calculation (vector calc)(sec): 1.13533333333333
III. Programmation:Creation of a 3000x3000 Hilbert matrix (matrix calc): 0.743333333333335
III. Programmation:Grand common divisors of 400,000 pairs (recursion): 4.21633333333333
III. Programmation:Creation of a 500x500 Toeplitz matrix (loops): 1.23666666666668
III. Programmation:Escoufier's method on a 45x45 matrix (mixed): 0.717999999999989
TOTAL:Total time for all 15 tests: 26.8783333333333
TOTAL:Overall mean (sum of I, II and III trimmed means/3): 1.37701279516068
I. Matrix calculation:Creation, transp., deformation of a 2500x2500 matrix: 1.89
I. Matrix calculation:2400x2400 normal distributed random matrix ^1000: 0.750333333333333
I. Matrix calculation:Sorting of 7,000,000 random values: 1.087
I. Matrix calculation:2800x2800 cross-product matrix (b = a' * a): 2.55766666666667
I. Matrix calculation:Linear regr. over a 3000x3000 matrix (c = a \ b'): 1.28533333333333
II. Matrix functions:FFT over 2,400,000 random values: 0.851999999999999
II. Matrix functions:Eigenvalues of a 640x640 random matrix: 0.859
II. Matrix functions:Determinant of a 2500x2500 random matrix: 1.13533333333333
II. Matrix functions:Cholesky decomposition of a 3000x3000 matrix: 1.03333333333333
II. Matrix functions:Inverse of a 1600x1600 random matrix: 1.20533333333333
III. Programmation:3,500,000 Fibonacci numbers calculation (vector calc)(sec): 1.12033333333333
III. Programmation:Creation of a 3000x3000 Hilbert matrix (matrix calc): 0.736000000000004
III. Programmation:Grand common divisors of 400,000 pairs (recursion): 4.667
III. Programmation:Creation of a 500x500 Toeplitz matrix (loops): 1.34633333333333
III. Programmation:Escoufier's method on a 45x45 matrix (mixed): 0.982
TOTAL:Total time for all 15 tests: 21.507
TOTAL:Overall mean (sum of I, II and III trimmed means/3): 1.16462514246633
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment