Using Ruby's Benchmark Library to Efficiently Rebuild the Max Method

In this coding exercise, we walk through how to efficiently find the largest item in an array. Additionally, we examine how to implement performance tests to compare two different implementation options.

Sign Up to Start Your Own Code Camp

Using Ruby Benchmark

Summary

Implement a method that finds the largest integer in an array without using Ruby's built-in max method. Additionally, ensure that the algorithm can work efficiently on large sets of data.

Exercise File

Code File

Exercise Description

Given the following array:

[1, 6, 3, 10, 5, 3]

Write a program that returns the largest integer in the array.

Example Output

10

Real World Usage

Finding the largest element in a collection is used in many algorithms. Additionally, you'll discover that there are multiple solutions to this exercise, however, not all of the solutions are efficient. Working through this exercise should help you analyze the performance of each implementation option. And performance analysis is important in day to day development.

Solution

Can be found on the solutions branch on github.

Jordan Hudgens

Jordan Hudgens

I've been a software engineer for the past decade and have traveled the world building applications and training individuals on a wide variety of topics.


View All Posts