Accessing TextField.text is slower than a bag of dried apricots
I always assumed accessing TextField.text would be slow, since we’re warned against TextField.text += String in the ASDocs, but I didn’t realize how slow. I switched to my test project for a quick verification. Lo and behold, it’s over 11 times slower than storing to a String variable and accessing that. Here are the results and test code:
TextField.text.................................454 (100000 iterations) text............................................41 (100000 iterations) bag of dried apricots..........................376 (100000 iterations)
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 | package { import com.gskinner.utils.PerformanceTest; import flash.display.Sprite; import flash.text.TextField; import flash.utils.setTimeout; public class Test extends Sprite { public var p:PerformanceTest; public var textfield:TextField; public var text:String; public function Test() { p = PerformanceTest.getInstance(); textfield = new TextField(); textfield.text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. " + "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, " + "when an unknown printer took a galley of type and scrambled it to make a type " + "specimen book. It has survived not only five centuries, but also the leap into " + "electronic typesetting, remaining essentially unchanged. It was popularised in " + "the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, " + "and more recently with desktop publishing software like Aldus PageMaker " + "including versions of Lorem Ipsum."; text = textfield.text; setTimeout(run, 1000); } public function run():void { p.testFunction(testTextFieldText, 100000); p.testFunction(testText, 100000); } public function testTextFieldText():void { textfield.text; } public function testText():void { text; } } } |


