11const graphGenerator = require ( './graph-generator' ) ;
22const utils = require ( './../utils' ) ;
3- const get = require ( './..ajax/get' ) ;
3+ const get = require ( './../server/ ajax/get' ) ;
44const Server = require ( './../server' ) ;
5- const graphs = graphGenerator ( ) ;
65
76
8- const measureExecutionTime = ( code ) => {
7+ const algorithmsCode = new Map ( ) ;
8+ const algorithmsMeasure = new Map ( ) ;
9+ const loadAlgorithms = ( problem , algorithms ) => {
10+ return Promise . all ( algorithms . map ( algorithm => {
11+ var codeDir = utils . getFileDir ( problem , algorithm , problem ) ;
12+ return get ( `${ codeDir } pure-code.js` ) . then ( code => algorithmsCode . set ( algorithm , code ) )
13+ } ) ) ;
14+ } ;
15+
16+ const measureExecutionTime = ( graph , code ) => {
17+ var algo = new Function ( "G" , code ) ;
918 const start = performance . now ( ) ;
10- eval ( code ) ;
19+ algo ( graph ) ;
1120 const end = performance . now ( ) ;
1221 return end - start ;
1322} ;
1423
15- // const runAlgorithms = (problem, algorithms) => {
16- // for(var graph in graphs){
17- // for(var algorithm in algorithmsNames){
18- // var codeDir = utils.getFileDir(problem, algorithm, problem);
19- // get(`${codeDir}code.js`).then((code) => {
20- // var executionTime = measureExecutionTime(code);
21- // })
22- // }
23- // }
24- // }
24+ const runAlgorithms = ( problem , algorithms , startSize , endSize ) => {
25+ const graphs = graphGenerator ( startSize , endSize ) ;
26+ return loadAlgorithms ( problem , algorithms ) . then ( ( ) => {
27+ for ( var graph of graphs ) {
28+ algorithms . forEach ( ( algorithm ) => {
29+ let executionTime = measureExecutionTime ( graph , algorithmsCode . get ( algorithm ) ) ;
30+ algorithmsMeasure . set ( algorithm , { graph, executionTime } ) ;
31+ } ) ;
32+ }
33+
34+ return algorithmsMeasure ;
35+ } ) ;
36+ } ;
37+
38+ module . exports = runAlgorithms ;
0 commit comments