This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
forked from carrotsearch/hppc
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #27 : Added Fastutil object bench
+ fixed Benchmarks again, benchmarking is hard dammit !
- Loading branch information
vsonnier
committed
Feb 1, 2015
1 parent
03faeef
commit 9bcae04
Showing
10 changed files
with
313 additions
and
68 deletions.
There are no files selected for viewing
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
123 changes: 123 additions & 0 deletions
123
hppcrt-benchmarks/src/main/java/com/carrotsearch/hppcrt/FastUtilObjectMap.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package com.carrotsearch.hppcrt; | ||
|
||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; | ||
|
||
import java.util.Random; | ||
|
||
public class FastUtilObjectMap extends MapImplementation<Object2IntOpenHashMap<MapImplementation.ComparableInt>> | ||
{ | ||
|
||
private ComparableInt[] insertKeys; | ||
private ComparableInt[] containsKeys; | ||
private ComparableInt[] removedKeys; | ||
private int[] insertValues; | ||
|
||
protected FastUtilObjectMap(final int size, final float loadFactor) | ||
{ | ||
super(new Object2IntOpenHashMap<ComparableInt>(size, loadFactor)); | ||
} | ||
|
||
/** | ||
* Setup | ||
*/ | ||
@Override | ||
public void setup(final int[] keysToInsert, final MapImplementation.HASH_QUALITY hashQ, final int[] keysForContainsQuery, final int[] keysForRemovalQuery) { | ||
|
||
final Random prng = new XorShiftRandom(0x122335577L); | ||
|
||
this.insertKeys = new ComparableInt[keysToInsert.length]; | ||
|
||
this.containsKeys = new ComparableInt[keysForContainsQuery.length]; | ||
this.removedKeys = new ComparableInt[keysForRemovalQuery.length]; | ||
|
||
this.insertValues = new int[keysToInsert.length]; | ||
|
||
//Auto box into Integers, they must have the same length anyway. | ||
for (int i = 0; i < keysToInsert.length; i++) { | ||
|
||
this.insertKeys[i] = new ComparableInt(keysToInsert[i], hashQ); | ||
|
||
this.insertValues[i] = prng.nextInt(); | ||
} | ||
|
||
//Auto box into Integers | ||
for (int i = 0; i < keysForContainsQuery.length; i++) { | ||
|
||
this.containsKeys[i] = new ComparableInt(keysForContainsQuery[i], hashQ); | ||
} | ||
|
||
//Auto box into Integers | ||
for (int i = 0; i < keysForRemovalQuery.length; i++) { | ||
|
||
this.removedKeys[i] = new ComparableInt(keysForRemovalQuery[i], hashQ); | ||
} | ||
|
||
//don't make things too easy, shuffle it so the bench do some pointer chasing in memory. | ||
//for the inserted keys | ||
|
||
Util.shuffle(this.insertKeys, prng); | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
this.instance.clear(); | ||
} | ||
|
||
@Override | ||
public int size() { | ||
|
||
return this.instance.size(); | ||
} | ||
|
||
@Override | ||
public int benchPutAll() { | ||
|
||
final Object2IntOpenHashMap<ComparableInt> instance = this.instance; | ||
final int[] values = this.insertValues; | ||
|
||
int count = 0; | ||
|
||
final ComparableInt[] keys = this.insertKeys; | ||
|
||
for (int i = 0; i < keys.length; i++) { | ||
|
||
count += instance.put(keys[i], values[i]); | ||
} | ||
|
||
return count; | ||
} | ||
|
||
@Override | ||
public int benchContainKeys() | ||
{ | ||
final Object2IntOpenHashMap<ComparableInt> instance = this.instance; | ||
|
||
int count = 0; | ||
|
||
final ComparableInt[] keys = this.containsKeys; | ||
|
||
for (int i = 0; i < keys.length; i++) { | ||
|
||
count += instance.containsKey(keys[i]) ? 1 : 0; | ||
} | ||
|
||
return count; | ||
} | ||
|
||
@Override | ||
public int benchRemoveKeys() { | ||
|
||
final Object2IntOpenHashMap<ComparableInt> instance = this.instance; | ||
|
||
int count = 0; | ||
|
||
final ComparableInt[] keys = this.removedKeys; | ||
|
||
for (int i = 0; i < keys.length; i++) { | ||
|
||
count += instance.removeInt(keys[i]); | ||
} | ||
|
||
return count; | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.