Skip to content

About

No description, website, or topics provided.

Resources

Stars

5 stars

Watchers

0 watching

Forks

Latest commit

 

History

10 Commits

Folders and files

Repository files navigation

What’s the best way to find the max int in an array?

TLDR array.max() wins

Solution 1

array.max()

Solution 2

(array as AnyObject).value(forKeyPath: "@max.self") as? Int

Solution 3A

array.max(by: < )

Solution 3B

array.max(by: { $0 < $1 })

Solution 4A

array.reduce(Int.min, max)

Solution 4B

array.reduce(Int.min, { max($0, $1) })

Solution 5

array.sorted().last!

Results

For array with 100000 elements with maxValue 100000

Solution 1 average: 0.051

Solution 2 average: 0.104

Solution 3A average: 0.058

Solution 3B average: 2.359

Solution 4A average: 0.074

Solution 4B average: 2.587

Solution 5 average: 1.244

About

No description, website, or topics provided.

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages