Created
March 25, 2011 17:43
-
-
Save wolever/887254 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"> | |
<mx:Script><![CDATA[ | |
import mx.charts.AreaChart; | |
import mx.messaging.Producer; | |
import utils.Timeit; | |
import utils.assert; | |
import utils.cartesian_product; | |
import utils.create; | |
import utils.curried; | |
import utils.map; | |
import utils.printf; | |
function testInnerArray(search:String):Boolean { | |
return ["a", "b", "c", "d"].indexOf(search) >= 0; | |
} | |
var sss:Array = ["a", "b", "c", "d"]; | |
function testOutterArray(search:String):Boolean { | |
return sss.indexOf(search) >= 0; | |
} | |
function testInnerObj(search:String):Boolean { | |
return { a: true, b: true, c: true, d: true }[search]; | |
} | |
var o:Object = { a: true, b: true, c: true, d: true }; | |
function testOutterObj(search:String):Boolean { | |
return o[search]; | |
} | |
var d:Dictionary = create(Dictionary, { a: true, b: true, c: true, d: true }); | |
function testOutterDict(search:String):Boolean { | |
return d[search]; | |
} | |
function testOrChaining(search:String):Boolean { | |
return search == "a" || search == "b" || | |
search == "c" || search == "d"; | |
} | |
]]></mx:Script> | |
<mx:creationComplete><![CDATA[ | |
var self:* = this; | |
var tests:Array = map(function(x:Array):Array { | |
var fname:String = x[0]; | |
var input:String = x[1]; | |
return [printf("%s('%s')", fname, input), | |
curried(self[fname], input)]; | |
}, cartesian_product( | |
["testInnerArray", "testOutterArray", "testInnerObj", | |
"testOutterObj", "testOutterDict", "testOrChaining"], | |
["a", "d", "e"] | |
)); | |
Timeit.traceMany(tests); | |
]]></mx:creationComplete> | |
</mx:Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[SWF] Users:wolever:Workspace:Test:bin-debug:Test.swf - 646,430 bytes after decompression | |
running 18 functions 100000 times... | |
testInnerArray('a'): 472, 478, 468 | |
testInnerArray('d'): 470, 476, 481 | |
testInnerArray('e'): 473, 484, 476 | |
testOutterArray('a'): 408, 417, 409 | |
testOutterArray('d'): 415, 428, 421 | |
testOutterArray('e'): 419, 423, 430 | |
testInnerObj('a'): 473, 464, 475 | |
testInnerObj('d'): 471, 504, 477 | |
testInnerObj('e'): 474, 473, 478 | |
testOutterObj('a'): 374, 375, 382 | |
testOutterObj('d'): 369, 374, 376 | |
testOutterObj('e'): 366, 374, 376 | |
testOutterDict('a'): 369, 375, 379 | |
testOutterDict('d'): 367, 375, 376 | |
testOutterDict('e'): 375, 378, 413 | |
testOrChaining('a'): 347, 352, 355 | |
testOrChaining('d'): 356, 368, 368 | |
testOrChaining('e'): 361, 366, 367 | |
done! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment