Libraryless. Click here for Pure Java version (5772L/32K).
1 | // This is not that great. 31 mill/s cache lookups. |
2 | // bench_concurrentHashMapBasedMethodCache_tweaked is still the best |
3 | // (48 mill/s), at least with concurrency level 1. |
4 | // |
5 | // The advantage of ClassValue though is that it doesn't have to be |
6 | // cleaned regularly if I understand this correctly. |
7 | |
8 | scope bench_classValueBasedMethodCache |
9 | |
10 | static long #cachesMade; |
11 | |
12 | static final ClassValue<_MethodCache> methodCacheClassValue = new { |
13 | @Override |
14 | protected _MethodCache computeValue(Class<?> type) { |
15 | ++cachesMade; |
16 | ret new _MethodCache(type); |
17 | } |
18 | }; |
19 | |
20 | static _MethodCache getMethodCache_cv(Class c) { |
21 | ret methodCacheClassValue.get(c); |
22 | } |
23 | |
24 | svoid bench_classValueBasedMethodCache(int nClasses default 1000) { |
25 | print("Loading " + nClasses(nClasses)); |
26 | L<Class> classes = map classForName(takeFirst(nClasses, classNamesInJigsawModule("java.base"))); |
27 | print("Have " + nClasses(classes) + ". Filling method caches"); |
28 | print(+cachesMade); |
29 | |
30 | time { |
31 | for (c : classes) assertNotNull(getMethodCache_cv(c)); |
32 | } |
33 | |
34 | print(+cachesMade); |
35 | |
36 | print("Looking them up again."); |
37 | benchFor10(-> { |
38 | for (c : classes) assertNotNull(getMethodCache_cv(c)); |
39 | }); |
40 | |
41 | print(+cachesMade); |
42 | } |
Began life as a copy of #1034270
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034271 |
Snippet name: | bench_classValueBasedMethodCache |
Eternal ID of this version: | #1034271/10 |
Text MD5: | 7bafdd41c3c5391551961036cb903630 |
Transpilation MD5: | 6d7245baa891cab392a2c4ba87fb0689 |
Author: | stefan |
Category: | javax / performance |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-01-31 18:45:36 |
Source code size: | 1229 bytes / 42 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 142 / 243 |
Version history: | 9 change(s) |
Referenced in: | [show references] |