Skip to content

Instantly share code, notes, and snippets.

@osscontributor
Created July 13, 2014 03:27
Show Gist options
  • Save osscontributor/1a30d1c1b23d2fd4ee9d to your computer and use it in GitHub Desktop.
Save osscontributor/1a30d1c1b23d2fd4ee9d to your computer and use it in GitHub Desktop.
@Grab(group='org.gperfutils', module='gbench', version='0.4.2-groovy-2.1')
def smallList = [[first: 'John', last: 'test']]
def largListWithMatchAtEnd = []
10000.times { largListWithMatchAtEnd << [first: 'Johnx', last: 'test'] }
largListWithMatchAtEnd << [first: 'John', last: 'test']
def largListWithMatchInCenter = []
5000.times { largListWithMatchInCenter << [first: 'Johnx', last: 'test'] }
largListWithMatchInCenter << [first: 'John', last: 'test']
5000.times { largListWithMatchInCenter << [first: 'Johnx', last: 'test'] }
def largeListWithMatchFirst = []
largeListWithMatchFirst << [first: 'John', last: 'test']
10000.times { largeListWithMatchFirst << [first: 'Johnx', last: 'test'] }
def r = benchmark {
'findTestWithSmallerListSize' {
smallList.find { it.first == 'John' } ? true : false
}
'inListTestWithSmallerListSize' {
'John' in smallList*.first
}
'findTestWithMatchPresentInEnd' {
largListWithMatchAtEnd.find { it.first == 'John' } ? true : false
}
'inListTestWithMatchPresentInEnd' {
'John' in largListWithMatchAtEnd*.first
}
'findTestWithMatchPresentInAverageCenter' {
largListWithMatchInCenter.find { it.first == 'John' } ? true : false
}
'inListTestWithMatchPresentInAverageCenter' {
'John' in largListWithMatchInCenter*.first
}
'findTestWithMatchPresentInFirst' {
largeListWithMatchFirst.find { it.first == 'John' } ? true : false
}
'inListTestWithMatchPresentInFirst' {
'John' in largeListWithMatchFirst*.first
}
}
r.prettyPrint()
Environment
===========
* Groovy: 2.3.3
* JVM: Java HotSpot(TM) 64-Bit Server VM (24.45-b08, Oracle Corporation)
* JRE: 1.7.0_45
* Total Memory: 245.5 MB
* Maximum Memory: 2731 MB
* OS: Mac OS X (10.9.4, x86_64)
Options
=======
* Warm Up: Auto (- 60 sec)
* CPU Time Measurement: On
user system cpu real
findTestWithSmallerListSize 372 0 372 372
inListTestWithSmallerListSize 338 0 338 338
findTestWithMatchPresentInEnd 856193 380 856573 856573
inListTestWithMatchPresentInEnd 853865 320 854185 854191
findTestWithMatchPresentInAverageCenter 427916 474 428390 428453
inListTestWithMatchPresentInAverageCenter 840076 700 840776 840776
findTestWithMatchPresentInFirst 330 0 330 330
inListTestWithMatchPresentInFirst 837291 1028 838319 838412
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment