# Sound performance

**URL:** <https://forum.kirupa.com/t/sound-performance/282586>\
**Category:** flash\
**Created:** [February 23, 2009, 11:26pm UTC](https://forum.kirupa.com/t/sound-performance/282586 "2009-02-23T23:26:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![justkevin](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@justkevin](https://forum.kirupa.com/u/justkevin)\
**Post date:** [February 23, 2009, 11:26pm UTC](https://forum.kirupa.com/t/sound-performance/282586/1 "2009-02-23T23:26:42Z")

</div>

While profiling the game I’m working on, I was surprised to discover that a very large chunk of my app’s performance cost comes from sound. After some tests, it seems that starting a single new sound playing takes more time than updating all the game’s enemies, projectiles, particles, animations, collision detection, etc. Here’s a simplified performance test:

```php

        public function playSound():void
        {
            var start:int = flash.utils.getTimer();
            this.sound.play(); // this.sound is an embedded Sound.
            var end:int = flash.utils.getTimer();
            trace(end-start); // Averages about 9ms
        }

```

and

```php
 public function doMath():void
        {
            var start:int = flash.utils.getTimer();
            for(var i:int = 0;i < 15000;i++)
            {
                var x:Number = Math.cos(Math.random());
            }
            var end:int = flash.utils.getTimer();
            trace(end-start); // Averages about 7ms
        }

```

The first, “playSound” averages around 9ms per call over a few hundred calls. This is just starting the sound playing once.

The second, “doMath” is _faster_, despite the fact that it’s generating 15,000 random numbers and calculating their cosines.

My questions:

Are these numbers about right? And, if so, is there any way to improve the performance of sound.play()?
