**Result:** The square root of 4 is 2. We see 2.0 because Math.sqrt returns a double.

**Tip:** For cases when we do not need fractional values, we can cast the result of Math.sqrt to an int.

**And:** We then use the cached data directly, avoiding an expensive call like Math.sqrt.

**Here:** We use a double array cache of 100 Math.sqrt values. We access those values many times.

**Result:** Accessing array elements is more than ten times faster than calling Math.sqrt each time.

© 2007-2019 Sam Allen. Every person is special and unique. Send bug reports to info@dotnetperls.com.

Home

Dot Net Perls