Bug 18400

Summary: Searching an array with indexOf is sometimes far slower than with a for loop
Product: [Mono] Class Libraries Reporter: Randall Schmidt <randall.schmidt>
Component: mscorlibAssignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: bugzilla.xamarin, joe.friedrichsen, mark, masafa, mono-bugs+monotouch, mono-bugs+mono, sebastien
Priority: ---    
Version: master   
Target Milestone: Untriaged   
Hardware: PC   
OS: Windows   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: Attached is the project we ran on Windows and the project we ran on the iPad as well as a spreadsheet comparing the runtimes of the tests.

Description Randall Schmidt 2014-03-14 12:40:42 UTC
Created attachment 6315 [details]
Attached is the project we ran on Windows and the project we ran on the iPad as well as a spreadsheet comparing the runtimes of the tests.

We noticed huge performance improvements when we changed some of our code from using indexOf to using for loops to find the index of an array entry on iPad.

In the case of searching a large enum array, a for loop is over 100x faster than indexOf.

On windows, searching a large enum array was 2.5 times faster with a for loop than with indexOf.

Attached is the project we ran on Windows and the project we ran on the iPad as well as a spreadsheet comparing the runtimes of the tests.
Comment 1 Sebastien Pouliot 2014-03-14 13:46:40 UTC
c.c. Mark
Comment 2 Marek Safar 2014-03-17 04:23:28 UTC
quite simple, we need custom equalitycomparer for enums as we have for strings
Comment 3 Marek Safar 2014-03-19 18:13:29 UTC
Fixed in master