-
Notifications
You must be signed in to change notification settings - Fork 9
/
benchmark.js
84 lines (64 loc) · 2.54 KB
/
benchmark.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//Authors : Peter Bock, Cecilia Ostertag
function benchmark(img, functionNameString, parameters, timeList, memoryList)
{
var startTime,endTime,time,memory;
IJ.freeMemory(); //run garbage collector
startTime = System.currentTimeMillis();
IJ.run(img, functionNameString, parameters);
endTime = System.currentTimeMillis();
time = endTime - startTime;
memory = IJ.currentMemory(); //memory currently being used by ImageJ
timeList.push(time);
memoryList.push(memory/1048576);//convert bytes to MB
}
function runBenchmark(imp, functionNameString, parameters)
{
IJ.log("Front loading...\n");
//------------------------------------FRONT-LOADING------------------------------
//front-load 5 times without saving the returned timing
var timeList=[],memoryList=[];
for(var i = 0; i<5; i++){
impDupl = imp.duplicate();
benchmark(impDupl,functionNameString,parameters,timeList, memoryList);
if(i==0)
{
IJ.log("first results :\n");
IJ.log("time: "+timeList[i]);
IJ.log("memory: "+memoryList[i]);
}
}
//IJ.run("Close All Windows", ""); //close all image windows
//------------------------------------BENCHMARKING------------------------------
IJ.log("Benchmarking the function "+functionNameString+"\n");
timeList = [];
memoryLsit = [];
var loops = 20;
for(var j = 0; j < loops; j++){
impDupl = imp.duplicate();
benchmark(impDupl,functionNameString,parameters,timeList, memoryList);
}
IJ.run("Close All Windows", "");
IJ.log("End of benchmark\n");
for(var i=0;i<timeList.length;i++)
{
IJ.log(functionNameString+","+timeList[i]+","+memoryList[i]+"\n");
}
IJ.log("\n");
}
// Main program
imgList=["/home/lyria/Edge-Detection-project/samples/Lenna_128.jpg","/home/lyria/Edge-Detection-project/samples/Lenna_256.jpg","/home/lyria/Edge-Detection-project/samples/Lenna_512.jpg","/home/lyria/Edge-Detection-project/samples/Lenna_1024.jpg","/home/lyria/Edge-Detection-project/samples/Lenna_2048.jpg"];
for (var j=0; j<imgList.length;j++)
{
functionNames = ["Find Edges","Log Filter","FeatureJ Laplacian","Canny Edge Detector","FeatureJ Edges"];
parametersList = ["","sigma=1.4 filterwidth=9 threshold=0 delta=0 mode=4","compute smoothing=1.4 detect","gaussian=2 low=2.5 high=5.0","compute smoothing=2.0 suppress lower=2.5 higher=5.0"];
for (var i=0;i<functionNames.length;i++)
{
imp = IJ.openImage(imgList[j]);
imp.show();
functionNameString = functionNames[i];
parameters = parametersList[i];
runBenchmark(imp, functionNameString, parameters);
IJ.freeMemory();
}
}
//runBenchmark(imp, functionNames[4], parametersList[4]);