… at least on my system. This past week I decided to upgrade my flocking simulation project to use the Flash 8 Point class. I had a 2D coordinate class, as I’m sure many people do, and I expected I’d retire it. But it turned out that changing over to flash.geom.Point slowed the app down considerably.
Here you can download a MyPoint class that conforms to the flash.geom.Point API, and the PointTest class I used to compare its performance to that of flash.geom.Point. I built the program with MTASC and with Flash 8. Both swfs had the same dimensions and fps.
Windows XP Pro, Pentium 4 2.80 GHz, 2GB RAM, Flash 8 standalone player
Average times in milliseconds: 5 runs of each swf, iterations = 10000 (Equals test: 10000 iterations with equal Points, 10000 iterations with unequal Points) swf built by: MTASC Flash 8 ------------ ------------ Point class: flash mine flash mine TEST Interpolate 520 349 524 357 Distance 724 154 711 166 Polar 557 363 548 379 Constructor 249 185 282 180 Clone 412 285 441 309 Offset 85 92 98 91 Equals 316 256 239 254 Subtract 420 308 465 346 Add 448 322 493 344 Normalize 281 263 272 271 ToString 147 152 173 170


that’s really bizarre. I’m guessing flash.geom.Point offloads a lot of its operations to the Matrix class, which would be slower than doing the simple math for most calculations. Still, since these classes are built into the player, I’d have thought they’d still have an advantage.
Comment by Keith Peters — September 26, 2005 @ 4:39 pm
Actually, some ppl decoded some parts of the flash player, and the flash.geom.* are implemented in actionscript, not as native methods. Their implementation is probably not the most optimized either, which is why you can write a faster version.
Comment by David R — September 27, 2005 @ 6:37 am
Thanks for sharing your Point class! However I found a small bug (or missing feature ;) > you only added getters for the x and y properties, no setters. For full compatiblity with flash.geom.Point those should be added.
Comment by Paul de Jong — July 22, 2006 @ 2:34 am