Skip to content

A command line tool built to test the performance of various anagram checking methods.

License

Notifications You must be signed in to change notification settings

jim-rhoades/Anagram

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Anagram

A command line tool built to test the performance of various anagram checking methods.

Included are multiple versions of the function:

func isAnagram(string1: String, string2: String) -> Bool {

}

Unit tests are also included to ensure that each version of isAnagram works as expected.

Rules

  • ignore capitalization (given the strings "cow" and "Cow", the function should return true)
  • ignore spaces (given the strings "Mia" and "I am", the function should return true)

Why?

During a job interview I was given a "whiteboard" code challenge with this problem. After the interview I was curious and wanted to find a way to solve it that performed well with large strings.

Some ideas came from various members of the iOS Developers Slack group.

Key take-aways

  • Version 2 (isAnagramV2) is the fastest, though it might not be the answer an interviewer is looking for during a whiteboard job interview.
  • Originally I had written this in a Playground, but performance testing in a Playground is generally not a good idea. Testing the compiled code via this command line tool provides more accurate results.
  • Performance differences between the debug build and release build can be dramatic. On my computer, isAnagramV2 takes 10s when running the debug build, and less than 1s for the release build. So, it's best to test performance on the release build.

About

A command line tool built to test the performance of various anagram checking methods.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages