Libraryless. Click here for Pure Java version (5776L/32K).
1 | static final new ConcurrentHashMap<Class, _MethodCache> getMethodCache_chm; |
2 | |
3 | static _MethodCache getMethodCache_chm(Class c) { |
4 | _MethodCache cache = getMethodCache_chm.get(c); |
5 | if (cache == null) |
6 | getMethodCache_chm.put(c, cache = _MethodCache(c)); |
7 | ret cache; |
8 | } |
9 | |
10 | // This one gets ~44 mill/s cache lookups which is definitely better than the old method |
11 | svoid bench_concurrentHashMapBasedMethodCache() { |
12 | print("Loading 1000 classes"); |
13 | L<Class> classes = map classForName(takeFirst(1000, classNamesInJigsawModule("java.base"))); |
14 | print("Have " + nClasses(classes) + ". Filling method caches"); |
15 | time { |
16 | for (c : classes) assertNotNull(getMethodCache_chm(c)); |
17 | } |
18 | print("Looking them up again."); |
19 | benchFor5(-> { |
20 | for (c : classes) assertNotNull(getMethodCache_chm(c)); |
21 | }); |
22 | |
23 | print("Classes in method cache: " + l(getMethodCache_chm)); |
24 | } |
Began life as a copy of #1034268
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034269 |
Snippet name: | bench_concurrentHashMapBasedMethodCache |
Eternal ID of this version: | #1034269/7 |
Text MD5: | ffaf7b3dd237d1bcb6f3b5f7cd1b7df5 |
Transpilation MD5: | 0177fbe762c32b5fc7b82e5a77314bc5 |
Author: | stefan |
Category: | javax / performance |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-01-29 15:57:14 |
Source code size: | 881 bytes / 24 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 136 / 213 |
Version history: | 6 change(s) |
Referenced in: | [show references] |