indexOf lastIndexOf 速度差
♥0 |
Line 59 |
Modified 2011-12-13 14:13:04 |
MIT License
archived:2017-03-29 11:36:43
ActionScript3 source code
/**
* Copyright yasurageruheya ( http://wonderfl.net/user/yasurageruheya )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/fNvg
*/
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.utils.getTimer;
public class FlashTest extends Sprite {
private const txt:TextField = new TextField();
private const COUNT:uint = 100000;
private const SAMPLE:String = "abcdefghijklmnopqrstuwxyz;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
private const FIRST:String = "abc";
private const LAST:String = "789";
public function FlashTest() {
txt.autoSize = "left";
// write as3 code here..
if (stage) init(null);
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
addChild(txt);
stage.addEventListener(MouseEvent.CLICK, test);
test(null);
}
private function test(e:MouseEvent):void
{
txt.text = "";
var i:int = COUNT;
var timer:int = getTimer();
while (i--)
{
if (SAMPLE.indexOf(FIRST) > -1) { }
}
txt.appendText("SAMPLE.indexOf(FIRST) : " + (getTimer() - timer) + "ms\n");
i = COUNT;
timer = getTimer();
while (i--)
{
if (SAMPLE.lastIndexOf(FIRST) > -1) { }
}
txt.appendText("SAMPLE.lastIndexOf(FIRST) : " + (getTimer() - timer) + "ms\n");
i = COUNT;
timer = getTimer();
while (i--)
{
if (SAMPLE.indexOf(LAST) > -1) { }
}
txt.appendText("SAMPLE.indexOf(LAST) : " + (getTimer() - timer) + "ms\n");
i = COUNT;
timer = getTimer();
while (i--)
{
if (SAMPLE.lastIndexOf(LAST) > -1) { }
}
txt.appendText("SAMPLE.lastIndexOf(LAST)" + (getTimer() - timer) + "ms\n");
txt.appendText("クリックで再計算");
}
}
}