diff options
author | Elliott Hughes <enh@google.com> | 2010-02-24 16:50:02 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2010-02-24 22:50:35 -0800 |
commit | a2ac9c490c37d9c802b2eeb212cf95ef8ed21e64 (patch) | |
tree | 745404b81f459708739b8b276c6f4647a70feab1 /docs | |
parent | 27eb24148a935d10c2c490205174c59a47e76dc6 (diff) | |
download | frameworks_base-a2ac9c490c37d9c802b2eeb212cf95ef8ed21e64.zip frameworks_base-a2ac9c490c37d9c802b2eeb212cf95ef8ed21e64.tar.gz frameworks_base-a2ac9c490c37d9c802b2eeb212cf95ef8ed21e64.tar.bz2 |
Remove incorrect/misleading irrelevancies from example code.
(I'll start checking in all my benchmarks -- not just the ones relevant to this
document -- somewhere under dalvik/libcore/ tomorrow, and we can see about
linking to them for those who want something they can actually run, or just
want to see the exact code that was benchmarked.)
Diffstat (limited to 'docs')
-rw-r--r-- | docs/html/guide/practices/design/performance.jd | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/docs/html/guide/practices/design/performance.jd b/docs/html/guide/practices/design/performance.jd index ab3b3d3..baed020 100644 --- a/docs/html/guide/practices/design/performance.jd +++ b/docs/html/guide/practices/design/performance.jd @@ -356,25 +356,19 @@ for loop syntax will be exactly equivalent to explicit iterator usage.</p> <p>There are several alternatives for iterating through an array:</p> -<pre>public class Foo { - int mSplat; -} -public class ArrayBenchmark { - Foo[] mArray = new Foo[27]; - { - for (int i = 0; i < mArray.length; ++i) { - mArray[i] = new Foo(); - } +<pre> static class Foo { + int mSplat; } + Foo[] mArray = ... - public static void zero() { + public void zero() { int sum = 0; for (int i = 0; i < mArray.length; ++i) { sum += mArray[i].mSplat; } } - public static void one() { + public void one() { int sum = 0; Foo[] localArray = mArray; int len = localArray.length; @@ -384,13 +378,13 @@ public class ArrayBenchmark { } } - public static void two() { + public void two() { int sum = 0; for (Foo a : mArray) { sum += a.mSplat; } } -}</pre> +</pre> <p><strong>zero()</strong> is slowest, because the JIT can't yet optimize away the cost of getting the array length once for every iteration through the |