Rev | Line | |
---|
[483] | 1 | <html> |
---|
| 2 | <head> |
---|
| 3 | <title>peller's test</title> |
---|
| 4 | <script type="text/javascript" src="../../../dojo/dojo.js"></script> |
---|
| 5 | <script type="text/javascript"> |
---|
| 6 | |
---|
| 7 | var lq = []; |
---|
| 8 | function log(s) { |
---|
| 9 | lq.push(s); |
---|
| 10 | //console.log(s); |
---|
| 11 | } |
---|
| 12 | |
---|
| 13 | function dumpLog() { |
---|
| 14 | dojo.forEach(lq, function(l) { console.log(l); }); |
---|
| 15 | lq = []; |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | dojo.addOnLoad(function() { |
---|
| 19 | forLoop(); |
---|
| 20 | forEachLoop(); |
---|
| 21 | forAgain(); |
---|
| 22 | forEachAgain(); |
---|
| 23 | dumpLog(); |
---|
| 24 | }); |
---|
| 25 | |
---|
| 26 | function forLoop() { |
---|
| 27 | var x=0; |
---|
| 28 | var a = g_a; |
---|
| 29 | var start=new Date(); |
---|
| 30 | for(var i=0;i<100000;i++){x=x+a[i];}; |
---|
| 31 | log("for loop elapsed:"+(new Date()-start)+" value="+x); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | function forEachLoop() { |
---|
| 35 | var x=0; |
---|
| 36 | var a = g_a; |
---|
| 37 | var start=new Date(); |
---|
| 38 | dojo.forEach(a, function(v,i){x=x+a[i];}); |
---|
| 39 | log("dojo.forEach elapsed:"+(new Date()-start)+" value="+x); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | function forAgain(){ |
---|
| 43 | log("for results:"); |
---|
| 44 | var start=new Date(); |
---|
| 45 | var x=0; |
---|
| 46 | for(var i=0;i<100000;i++){x=x+g_a[i];} |
---|
| 47 | log("elapsed:"+(new Date()-start)+" value="+x); |
---|
| 48 | } |
---|
| 49 | function forEachAgain(){ |
---|
| 50 | log("forEach results:"); |
---|
| 51 | var a = g_a; |
---|
| 52 | var x=0; |
---|
| 53 | var start=new Date(); |
---|
| 54 | a.forEach(function(v,i){x=x+a[i];}); |
---|
| 55 | log("elapsed:"+(new Date()-start)+" value="+x); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | var g_a = new Array(100000); |
---|
| 59 | for(var i=0; i<100000;i++){g_a[i]=i;} |
---|
| 60 | |
---|
| 61 | var start, x, i; |
---|
| 62 | log("inline for results:"); |
---|
| 63 | start=new Date(); |
---|
| 64 | x=0; |
---|
| 65 | for(i=0;i<100000;i++){x=x+g_a[i];} |
---|
| 66 | log("elapsed:"+(new Date()-start)+" value="+x); |
---|
| 67 | |
---|
| 68 | log("inline forEach results:"); |
---|
| 69 | start=new Date(); |
---|
| 70 | x=0; |
---|
| 71 | g_a.forEach(function(v,i){x=x+g_a[i];}); |
---|
| 72 | log("elapsed:"+(new Date()-start)+" value="+x); |
---|
| 73 | dumpLog(); |
---|
| 74 | </script> |
---|
| 75 | </head> |
---|
| 76 | <body> |
---|
| 77 | </body> |
---|
| 78 | </html> |
---|
Note: See
TracBrowser
for help on using the repository browser.