Libraryless. Click here for Pure Java version (5420L/30K).
1 | scope bench_reflectiveCallWithInternedMethodName. |
2 | |
3 | static long #what; |
4 | |
5 | svoid bench_reflectiveCallWithInternedMethodName() { |
6 | what = 0; |
7 | |
8 | class MyObj { |
9 | void veryLongMethodNameToIllustrateThePoint() { ++what; } |
10 | } |
11 | |
12 | S methodName = "veryLongMethodNameToIllustrateThePoint"; |
13 | |
14 | _MethodCache cache = callOpt_getCache(MyObj.class); |
15 | S nameInCache = firstThat(keys(cache.cache), name -> eq(name, methodName)); |
16 | print(nameInCache == methodName |
17 | ? "Name in cache is interned! (GOOD)" |
18 | : "Name in cache is NOT interned!! (so this is all pointless)"); |
19 | |
20 | embedded void benchCall(O o, S method) { |
21 | benchFor10(-> call(o, method)); |
22 | } |
23 | |
24 | print("string literal"); |
25 | benchCall(new MyObj, methodName); |
26 | print(what); |
27 | |
28 | print("constructed string"); |
29 | S methodName2 = firstToLower("VeryLongMethodNameToIllustrateThePoint"); |
30 | if (methodName2 != methodName && eq(methodName2, methodName)) print(" (yes they're different - but equal)"); |
31 | else fail("what!?"); |
32 | |
33 | benchCall(new MyObj, methodName2); |
34 | print(what); |
35 | |
36 | print("interned constructed string"); |
37 | S methodName3 = methodName2.intern(); |
38 | if (methodName3 == methodName) print(" (yes it's the same as the literal)"); |
39 | else warn("This is not good - interned is not same as literal"); |
40 | |
41 | benchCall(new MyObj, methodName3); |
42 | print(what); |
43 | } |
Began life as a copy of #1034262
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034267 |
Snippet name: | bench_reflectiveCallWithInternedMethodName |
Eternal ID of this version: | #1034267/8 |
Text MD5: | 2b400a7f19c5c5a0a2d7c5155d99e181 |
Transpilation MD5: | 9e956828f2d7837bc08eaae0325e4f18 |
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:29:10 |
Source code size: | 1354 bytes / 43 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 151 / 234 |
Version history: | 7 change(s) |
Referenced in: | [show references] |