Skip to content
Commit 4049d0fd authored by Kweku Adams's avatar Kweku Adams
Browse files

Improve forEach.

The default implementation of Collection.forEach() uses the
iterator(). Switch to a simple for loop iterating through the array
since the iterator is an inefficient way to access the array contents.

Benchmark results:

Before:

android.util.ArrayMapPerfTest#testForEach_Large:
	forEach_Large_min (ns): 599759
	forEach_Large_median (ns): 655845
	forEach_Large_mean (ns): 636927
	forEach_Large_standardDeviation: 34373
android.util.ArrayMapPerfTest#testForEach_Small:
	forEach_Small_min (ns): 118822
	forEach_Small_median (ns): 121422
	forEach_Small_mean (ns): 121695
	forEach_Small_standardDeviation: 2079

After:

android.util.ArrayMapPerfTest#testForEach_Large:
	forEach_Large_min (ns): 403562
	forEach_Large_median (ns): 441364
	forEach_Large_mean (ns): 442301
	forEach_Large_standardDeviation: 24917
android.util.ArrayMapPerfTest#testForEach_Small:
	forEach_Small_min (ns): 81889
	forEach_Small_median (ns): 87889
	forEach_Small_mean (ns): 86905
	forEach_Small_standardDeviation: 2880

Bug: 194098491
Test: atest CorePerfTests:ArrayMapPerfTest (see results above)
Test: atest CtsUtilTestCases:ArrayMapTest
Test: atest FrameworksCoreTests:ArrayMapTest
Change-Id: Id528fe24f1d17af01a2d639753d42e2ad21144d2
parent 1548f793
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment