Created
June 25, 2020 13:00
-
-
Save purplefox/1fbf34da356ede20f7f533ded98800dc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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