Last active
August 29, 2015 14:03
-
-
Save dmahapatro/0a4b785c80f11ee5dab1 to your computer and use it in GitHub Desktop.
Benchmark performance between find and in list to match a key-value from a map present in list.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab(group='com.googlecode.gbench', module='gbench', version='11.07.05') | |
def r = benchmark { | |
'findTestWithSmallerListSize' { | |
def myList = [[first: 'John', last: 'test']] | |
myList.find { it.first == 'John' } ? true : false | |
} | |
'inListTestWithSmallerListSize' { | |
def myList = [[first: 'John', last: 'test']] | |
'John' in myList*.first | |
} | |
'findTestWithMatchPresentInEnd' { | |
def myList = [] | |
10000.times { myList << [first: 'Johnx', last: 'test'] } | |
myList << [first: 'John', last: 'test'] | |
myList.find { it.first == 'John' } ? true : false | |
} | |
'inListTestWithMatchPresentInEnd' { | |
def myList = [] | |
10000.times { myList << [first: 'Johnx', last: 'test'] } | |
myList << [first: 'John', last: 'test'] | |
'John' in myList*.first | |
} | |
'findTestWithMatchPresentInAverageCenter' { | |
def myList = [] | |
5000.times { myList << [first: 'Johnx', last: 'test'] } | |
myList << [first: 'John', last: 'test'] | |
5000.times { myList << [first: 'Johnx', last: 'test'] } | |
myList.find { it.first == 'John' } ? true : false | |
} | |
'inListTestWithMatchPresentInAverageCenter' { | |
def myList = [] | |
5000.times { myList << [first: 'Johnx', last: 'test'] } | |
myList << [first: 'John', last: 'test'] | |
5000.times { myList << [first: 'Johnx', last: 'test'] } | |
'John' in myList*.first | |
} | |
'findTestWithMatchPresentInFirst' { | |
def myList = [] | |
myList << [first: 'John', last: 'test'] | |
10000.times { myList << [first: 'Johnx', last: 'test'] } | |
myList.find { it.first == 'John' } ? true : false | |
} | |
'inListTestWithMatchPresentInFirst' { | |
def myList = [] | |
myList << [first: 'John', last: 'test'] | |
10000.times { myList << [first: 'Johnx', last: 'test'] } | |
'John' in myList*.first | |
} | |
} | |
r.prettyPrint() | |
//Result | |
user system cpu real | |
findTestWithSmallerListSize 571 0 571 598 | |
inListTestWithSmallerListSize 411 0 411 411 | |
findTestWithMatchPresentInEnd 2714872 43 2714915 2739768 | |
inListTestWithMatchPresentInEnd 2266303 39 2266342 2431595 | |
findTestWithMatchPresentInAverageCenter 2141836 39 2141875 2263714 | |
inListTestWithMatchPresentInAverageCenter 2261387 37 2261424 2438485 | |
findTestWithMatchPresentInFirst 1667364 27 1667391 1813254 | |
inListTestWithMatchPresentInFirst 2288471 37 2288508 2425089 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment