############

[paste test results in R..]
[HINT: use log4j.appender.CONSOLE.Threshold=ERROR]
[first result assumed to be BIN]
[and, SKIPELEMENT should be FALSE]
[now use..]

# don't copy line below if you don't want a file
png(filename=paste("/Users/joerivandervelde/Desktop/", "plot.png"), height=1000, width=1000, bg="white")


ylim=c(1e+2,1e+8)
scale <- .8
names(bin) <- c('Write', 'Text_row', 'Text_col', 'Text_sublist', 'Text_suboffs', 'Deci_row', 'Deci_col', 'Deci_sublist', 'Deci_suboffs')

boxplot(bin, ylim=ylim, log = "y", col="snow2", cex.lab=scale, cex.axis=scale, cex.main=scale, main="Binary vs Database vs CSV vs Memory matrix performance", border="green4", ylab="Writing / reading speed (elements/sec)", xlab="Data type / retrieval method")
boxplot(db, col="snow2", cex.lab=scale, cex.axis=scale, cex.main=scale, border="orangered", add=TRUE, names=FALSE)
boxplot(file, col="snow2", cex.lab=scale, cex.axis=scale, cex.main=scale, border="darkgoldenrod3", add=TRUE, names=FALSE)
boxplot(memory, col="snow2", cex.lab=scale, cex.axis=scale, cex.main=scale, border="royalblue", add=TRUE, names=FALSE)
legend(x=1,y=1e+8, c("Bin","DB","CSV","Mem"), cex=1, col=c("green4","orangered","darkgoldenrod3","royalblue"), lty=1, lwd=3)

# don't copy line below if you don't want a file
dev.off()


############
Text_element	<- c(16349, 15623, 15548, 15404, 15526, 17897, 15867, 15570, 15641, 15472)
Text_row		<- c(333222, 329055, 362844, 346260, 351864, 354735, 351617, 334560, 355366, 348068)
Text_column		<- c(252270, 259807, 280112, 271886, 268672, 273000, 276243, 265957, 275785, 272108)
Text_submlist	<- c(256278, 243724, 251889, 253421, 242659, 248385, 258464, 245218, 256147, 251130)
Text_submoffs	<- c(296735, 293513, 304599, 307314, 310655, 305530, 309310, 291545, 305064, 304321)
Deci_element	<- c(12791, 12409, 11881, 11664, 12051, 11524, 12107, 12067, 11965, 11760)
Deci_row		<- c(450247, 441306, 456412, 451875, 448833, 442673, 459981, 450653, 471031, 455580)
Deci_column		<- c(320821, 319897, 328191, 331345, 314960, 328947, 335008, 325309, 343760, 335008)
Deci_submlist	<- c(361010, 356760, 362581, 335795, 351000, 349040, 360620, 349162, 358551, 348675)
Deci_submoffs	<- c(441501, 457456, 443458, 455788, 438981, 432152, 442477, 430477, 447227, 433087)

df_all <- data.frame(Text_element, Text_row, Text_column, Text_submlist, Text_submoffs, Deci_element, Deci_row, Deci_column, Deci_submlist, Deci_submoffs)
df_fast <- data.frame(Text_row, Text_column, Text_submlist, Text_submoffs, Deci_row, Deci_column, Deci_submlist, Deci_submoffs)
df_slow <- data.frame(Text_element, Deci_element)


boxplot(df_all, col=c(rep("chartreuse", 5),rep("burlywood1", 5)), ylab="Reading speed (elements/sec)", xlab="Data type / retrieval method")
boxplot(df_fast, col=c(rep("chartreuse", 4),rep("burlywood1", 4)), ylab="Reading speed (elements/sec)", xlab="Data type / retrieval method")
boxplot(df_slow, col=c("chartreuse", "burlywood1"), ylab="Reading speed (elements/sec)", xlab="Data type / retrieval method")

##############
#NEW TESTS AND DATA:

Write <- c(76923, 78431, 79402, 78628, 78431)
T_row <- c(381097, 381097, 381097, 381097, 381097)
T_col <- c(301932, 307503, 307881, 301932, 307881)
T_sublist <- c(285714, 320102, 319693, 313676, 319693)
T_suboffs <- c(363372, 400000, 355618, 355618, 421585)
D_row <- c(485436, 457038, 500000, 484496, 500000)
D_col <- c(381097, 372023, 363901, 372023, 380517)
D_sublist <- c(400000, 444839, 432525, 410509, 432525)
D_suboffs <- c(570776, 592417, 614250, 614250, 592417)

Write_db <- c(11847, 11130, 11412, 10136, 10081)
T_row_db <- c(41131, 39600, 40610, 40102, 30887)
T_col_db <- c(40303, 41666, 40400, 40303, 29356)
T_sublist_db <- c(28219, 28522, 27397, 28267, 26404)
T_suboffs_db <- c(285714, 296208, 296208, 290697, 307503)
D_row_db <- c(40816, 40709, 37125, 39314, 33615)
D_col_db <- c(37119, 37385, 36780, 36448, 24314)
D_sublist_db <- c(25847, 25890, 25890, 25805, 24316)
D_suboffs_db <- c(132275, 133333, 131164, 131164, 132205)

bin <- data.frame(Write, T_row, T_col, T_sublist, T_suboffs, D_row, D_col, D_sublist, D_suboffs)
db <- data.frame(Write_db, T_row_db, T_col_db, T_sublist_db, T_suboffs_db, D_row_db, D_col_db, D_sublist_db, D_suboffs_db)

#PLOT
boxplot(bin, col="snow2", cex.lab=.7, cex.axis=.7, cex.main=.7, main="Binary vs Database matrix performance", border=c("green4", rep("orangered", 8)), ylab="Writing / reading speed (elements/sec)", xlab="Data type / retrieval method", ylim=c(0,7E+5))
boxplot(db, col="snow2", cex.lab=.7, cex.axis=.7, cex.main=.7, border=c("darkgoldenrod3", rep("royalblue", 8)), add=TRUE, names=FALSE)
legend(x=1,y=7E+5, c("Binary writing","Database writing","Binary reading","Database reading"), cex=0.7, col=c("green4","darkgoldenrod3","orangered","royalblue"), lty=1); 

#SAME, BUT NOW EXPORT NICELY TO PNG
png(filename="/var/folders/Op/OpzgcAj5F7WsOfwQEOTuZk+++TI/-Tmp-/figure.png", height=800, width=800, bg="white")
boxplot(bin, col="snow2", cex.lab=1, cex.axis=1, cex.main=1, main="Binary vs Database matrix performance", border=c("green4", rep("orangered", 8)), ylab="Writing / reading speed (elements/sec)", xlab="Data type / retrieval method", ylim=c(0,7E+5))
boxplot(db, col="snow2", cex.lab=1, cex.axis=1, cex.main=1, border=c("darkgoldenrod3", rep("royalblue", 8)), add=TRUE, names=FALSE)
legend(x=1,y=7E+5, c("Binary writing","Database writing","Binary reading","Database reading"), cex=1, col=c("green4","darkgoldenrod3","orangered","royalblue"), lty=1); 
dev.off()





##############
#INCLUDING ELEMENT SPEEDS : NEW TESTS AND DATA:

Write <- c(76923, 78431, 79402, 78628, 78431)
T_elem <- c(5714, 5767, 5767, 5817, 5714)
T_row <- c(381097, 381097, 381097, 381097, 381097)
T_col <- c(301932, 307503, 307881, 301932, 307881)
T_sublist <- c(285714, 320102, 319693, 313676, 319693)
T_suboffs <- c(363372, 400000, 355618, 355618, 421585)
D_elem <- c(5665, 5662, 5927, 5868, 5871)
D_row <- c(485436, 457038, 500000, 484496, 500000)
D_col <- c(381097, 372023, 363901, 372023, 380517)
D_sublist <- c(400000, 444839, 432525, 410509, 432525)
D_suboffs <- c(570776, 592417, 614250, 614250, 592417)

Write_db <- c(11847, 11130, 11412, 10136, 10081)
T_elem_db <- c(939, 864, 892, 901, 901)
T_row_db <- c(41131, 39600, 40610, 40102, 30887)
T_col_db <- c(40303, 41666, 40400, 40303, 29356)
T_sublist_db <- c(28219, 28522, 27397, 28267, 26404)
T_suboffs_db <- c(285714, 296208, 296208, 290697, 307503)
D_elem_db <- c(919, 876, 868, 873, 888)
D_row_db <- c(40816, 40709, 37125, 39314, 33615)
D_col_db <- c(37119, 37385, 36780, 36448, 24314)
D_sublist_db <- c(25847, 25890, 25890, 25805, 24316)
D_suboffs_db <- c(132275, 133333, 131164, 131164, 132205)

bin <- data.frame(Write, T_elem, T_row, T_col, T_sublist, T_suboffs, D_elem, D_row, D_col, D_sublist, D_suboffs)
db <- data.frame(Write_db, T_elem_db, T_row_db, T_col_db, T_sublist_db, T_suboffs_db, D_elem_db, D_row_db, D_col_db, D_sublist_db, D_suboffs_db)

color3 <- "green4"
color2 <- "orangered"
color1 <- "darkorchid"
color6 <- "darkgoldenrod3"
color5 <- "royalblue"
color4 <- "navajowhite4"

#PLOT
boxplot(bin, col="snow2", cex.lab=.7, cex.axis=.7, cex.main=.7, main="Binary vs Database matrix performance", border=c(color1, rep(color2, 5), rep(color3, 5)), ylab="Writing / reading speed (elements/sec)", xlab="Data type / retrieval method", ylim=c(0,7E+5))
boxplot(db, col="snow2", cex.lab=.7, cex.axis=.7, cex.main=.7, border=c(color4, rep(color5, 5), rep(color6, 5)), add=TRUE, names=FALSE)
legend(x=1,y=7E+5, c("Binary writing","Database writing","Binary text reading","Database text reading","Binary double reading","Database double reading"), cex=0.7, col=c(color1,color4,color2,color5,color3,color6), lty=1); 

#ALSO, ZOOMED IN ON SMALL SCALE:
boxplot(bin, col="snow2", cex.lab=.7, cex.axis=.7, cex.main=.7, main="Binary vs Database matrix performance", border=c(color1, rep(color2, 5), rep(color3, 5)), ylab="Writing / reading speed (elements/sec)", xlab="Data type / retrieval method", ylim=c(0,5E+4))
boxplot(db, col="snow2", cex.lab=.7, cex.axis=.7, cex.main=.7, border=c(color4, rep(color5, 5), rep(color6, 5)), add=TRUE, names=FALSE)
legend(x=1,y=5E+4, c("Database writing","Binary text reading","Database text reading","Binary double reading","Database double reading"), cex=0.7, col=c(color4,color2,color5,color3,color6), lty=1); 


#SAME, BUT NOW EXPORT NICELY TO PNG
png(filename="/Users/joerivandervelde/Desktop/figure1.png", height=600, width=600, bg="white")
boxplot(bin, col="snow2", cex.lab=1, cex.axis=1, cex.main=1, main="Binary vs Database matrix performance", border=c(color1, rep(color2, 5), rep(color3, 5)), ylab="Writing / reading speed (elements/sec)", xlab="Data type / retrieval method", ylim=c(0,7E+5))
boxplot(db, col="snow2", cex.lab=1, cex.axis=1, cex.main=1, border=c(color4, rep(color5, 5), rep(color6, 5)), add=TRUE, names=FALSE)
legend(x=1,y=7E+5, c("Binary writing","Database writing","Binary reading","Database reading"), cex=1, col=c(color1,color4,color2,color5), lty=1); 
dev.off()

############# WORKING WITH JAVA AUTOMATION

colorBin <- "orangered"
colorDb <- "royalblue"
colorFile <- "green4"

Write <- c(0)
T_elem <- c(0)
T_row <- c(0)
T_col <- c(0)
T_sublist <- c(0)
T_suboffs <- c(0)
D_elem <- c(0)
D_row <- c(0)
D_col <- c(0)
D_sublist <- c(0)
D_suboffs <- c(0)
niceNames <- data.frame(Write, T_elem, T_row, T_col, T_sublist, T_suboffs, D_elem, D_row, D_col, D_sublist, D_suboffs)

T_elem_bin <- c(8605, 16977, 15698, 17421, 16977, 16977, 17094, 16977, 16233, 16806)
D_elem_bin <- c(5844, 5858, 12077, 11947, 12315, 5995, 5783, 12360, 11947, 12500)
T_elem_db <- c(1370, 1291, 1380, 1277, 1378, 1282, 1379, 1280, 1323, 1276)
D_elem_db <- c(1356, 1259, 1348, 1254, 1347, 1254, 1350, 1261, 1344, 1259)
T_elem_file <- c(488, 488, 488, 493, 489, 486, 488, 488, 487, 489)
D_elem_file <- c(167, 167, 167, 167, 167, 167, 167, 167, 167, 167)
Write_bin <- c(127746, 128435, 117481, 111209, 116849, 115526, 118934, 118427, 116306, 113404)
T_row_bin <- c(332889, 333333, 328515, 327225, 324675, 328947, 333778, 148898, 324254, 325520)
T_col_bin <- c(266808, 267094, 263991, 260688, 262054, 263713, 266240, 131027, 263157, 261233)
T_sublist_bin <- c(257201, 260145, 242013, 227479, 245821, 231053, 243427, 243190, 245821, 244140)
T_suboffs_bin <- c(275027, 320512, 291715, 283768, 295857, 287356, 293772, 291715, 291375, 293427)
D_row_bin <- c(433275, 430292, 434027, 436300, 439367, 430292, 431034, 439367, 438596, 438596)
D_col_bin <- c(332005, 336473, 334672, 336473, 333778, 330687, 332889, 345303, 335120, 335570)
D_sublist_bin <- c(356633, 359712, 322164, 351123, 323834, 354609, 346740, 351617, 325097, 323834)
D_suboffs_bin <- c(473484, 448833, 450450, 460405, 459558, 407830, 414593, 417362, 460405, 463821)
bin <- data.frame(Write_bin, T_elem_bin, T_row_bin, T_col_bin, T_sublist_bin, T_suboffs_bin, D_elem_bin, D_row_bin, D_col_bin, D_sublist_bin, D_suboffs_bin)
Write_db <- c(11894, 6981, 6957, 6952, 6831, 7464, 6913, 7259, 6830, 7138)
T_row_db <- c(49910, 44499, 43599, 44107, 43508, 43921, 43290, 42918, 42713, 44037)
T_col_db <- c(49940, 42800, 42676, 42517, 42955, 42786, 41548, 42764, 41569, 41792)
T_sublist_db <- c(30380, 27873, 29373, 28283, 29178, 27802, 29335, 27889, 29708, 27100)
T_suboffs_db <- c(258264, 254065, 253807, 254065, 251256, 255102, 249500, 255623, 257201, 252525)
D_row_db <- c(42574, 37180, 36889, 37114, 36867, 36775, 36002, 36748, 35658, 36835)
D_col_db <- c(42582, 37064, 36699, 36911, 36289, 36716, 36284, 36656, 35648, 36581)
D_sublist_db <- c(27221, 27129, 26675, 26706, 26438, 26974, 25767, 26497, 26296, 26544)
D_suboffs_db <- c(132275, 134698, 134770, 133976, 133404, 133262, 132696, 133832, 131164, 134916)
db <- data.frame(Write_db, T_elem_db, T_row_db, T_col_db, T_sublist_db, T_suboffs_db, D_elem_db, D_row_db, D_col_db, D_sublist_db, D_suboffs_db)
Write_file <- c(226963, 233535, 237304, 227169, 233208, 227169, 226757, 220555, 236854, 228623)
T_row_file <- c(11814, 11873, 11903, 11877, 11888, 11930, 11888, 11846, 11894, 11869)
T_col_file <- c(10345, 10277, 10367, 10338, 10268, 10360, 10217, 10382, 10298, 10205)
T_sublist_file <- c(311332, 323415, 329815, 325520, 330250, 329380, 318066, 349650, 355618, 322997)
T_suboffs_file <- c(1700680, 3164556, 1724137, 3246753, 1798561, 3289473, 2941176, 1736111, 1984126, 3246753)
D_row_file <- c(3924, 3926, 3935, 3934, 3928, 3911, 3919, 3943, 3933, 3906)
D_col_file <- c(3163, 3162, 3176, 3178, 3145, 3177, 3166, 3148, 3159, 3123)
D_sublist_file <- c(288683, 292397, 292056, 285388, 289017, 291036, 293083, 293427, 293083, 312891)
D_suboffs_file <- c(1412429, 1082251, 1059322, 980392, 1024590, 1077586, 1054852, 1037344, 1054852, 1082251)
file <- data.frame(Write_file, T_elem_file, T_row_file, T_col_file, T_sublist_file, T_suboffs_file, D_elem_file, D_row_file, D_col_file, D_sublist_file, D_suboffs_file)

boxplot(niceNames, cex.lab=.7, cex.axis=.7, cex.main=.7, main="Alternative XGAP datamatrix backends: Binary, database and plainfile performance comparison\nBenchmark system: AMD Quadcore, 64 bit, 4 GB ram, MS Windows, mildly stressed", border="white", ylab="Writing / reading speed (elements/sec)", xlab="Data type / retrieval method", ylim=c(100,max(bin, db, file)), log="y")
boxplot(bin, col="snow2", cex.lab=.7, cex.axis=.7, cex.main=.7, border=colorBin, add=TRUE, names=FALSE)
boxplot(db, col="snow2", cex.lab=.7, cex.axis=.7, cex.main=.7, border=colorDb, add=TRUE, names=FALSE)
boxplot(file, col="snow2", cex.lab=.7, cex.axis=.7, cex.main=.7, border=colorFile, add=TRUE, names=FALSE)
legend(x=1,y=3E+6, c("Binary write/read","Database write/read","File write/read"), cex=0.7, col=c(colorBin,colorDb,colorFile), lty=1); 
