Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

43
LINES

< > BotCompany Repo | #1034267 // bench_reflectiveCallWithInternedMethodName

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (5420L/30K).

scope bench_reflectiveCallWithInternedMethodName.

static long #what;

svoid bench_reflectiveCallWithInternedMethodName() {
  what = 0;
  
  class MyObj {
    void veryLongMethodNameToIllustrateThePoint() { ++what; }
  }
  
  S methodName = "veryLongMethodNameToIllustrateThePoint";
  
  _MethodCache cache = callOpt_getCache(MyObj.class);
  S nameInCache = firstThat(keys(cache.cache), name -> eq(name, methodName));
  print(nameInCache == methodName
    ? "Name in cache is interned! (GOOD)"
    : "Name in cache is NOT interned!! (so this is all pointless)");
  
  embedded void benchCall(O o, S method) {
    benchFor10(-> call(o, method));
  }

  print("string literal");
  benchCall(new MyObj, methodName);
  print(what);
  
  print("constructed string");
  S methodName2 = firstToLower("VeryLongMethodNameToIllustrateThePoint");
  if (methodName2 != methodName && eq(methodName2, methodName)) print("  (yes they're different - but equal)");
  else fail("what!?");
  
  benchCall(new MyObj, methodName2);
  print(what);
  
  print("interned constructed string");
  S methodName3 = methodName2.intern();
  if (methodName3 == methodName) print("  (yes it's the same as the literal)");
  else warn("This is not good - interned is not same as literal");
  
  benchCall(new MyObj, methodName3);
  print(what);
}

Author comment

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: 152 / 234
Version history: 7 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1034268 - bench_getMethodCacheForClass