Skip to content

Instantly share code, notes, and snippets.

@purplefox
Created June 25, 2020 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save purplefox/1fbf34da356ede20f7f533ded98800dc to your computer and use it in GitHub Desktop.
Save purplefox/1fbf34da356ede20f7f533ded98800dc to your computer and use it in GitHub Desktop.
package scratch;
import java.util.HashMap;
import java.util.Map;
public class StartsWithPerf {
public static void main(String[] args) {
try {
new StartsWithPerf().go();
} catch (Exception e) {
e.printStackTrace();
}
}
public void go() throws Exception {
Map<String, String> map = new HashMap();
int numApps = 1000;
int numTopicsPerApp = 10000;
for (int i = 0; i < numApps; i++) {
for (int j = 0; j < numTopicsPerApp; j++) {
String key = String.format("tenant1_app%d_topic%d", i, j);
map.put(key, key);
}
}
for (int i = 0; i < 1000; i++) {
long start = System.currentTimeMillis();
int count = 0;
for (Map.Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
if (key.startsWith("tenant1_app23_")) {
count++;
}
}
long end = System.currentTimeMillis();
System.out.println("Count is " + count + " duration " + (end - start));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment