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

42
LINES

< > BotCompany Repo | #1034271 // bench_classValueBasedMethodCache

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

Libraryless. Click here for Pure Java version (5772L/32K).

// This is not that great. 31 mill/s cache lookups.
// bench_concurrentHashMapBasedMethodCache_tweaked is still the best
// (48 mill/s), at least with concurrency level 1.
//
// The advantage of ClassValue though is that it doesn't have to be
// cleaned regularly if I understand this correctly.

scope bench_classValueBasedMethodCache

static long #cachesMade;

static final ClassValue<_MethodCache> methodCacheClassValue = new {
  @Override
  protected _MethodCache computeValue(Class<?> type) {
    ++cachesMade;
    ret new _MethodCache(type);
  }
};
  
static _MethodCache getMethodCache_cv(Class c) {
  ret methodCacheClassValue.get(c);
}

svoid bench_classValueBasedMethodCache(int nClasses default 1000) {
  print("Loading " + nClasses(nClasses));
  L<Class> classes = map classForName(takeFirst(nClasses, classNamesInJigsawModule("java.base")));
  print("Have " + nClasses(classes) + ". Filling method caches");
  print(+cachesMade);
  
  time {
    for (c : classes) assertNotNull(getMethodCache_cv(c));
  }
  
  print(+cachesMade);
  
  print("Looking them up again.");
  benchFor10(-> {
    for (c : classes) assertNotNull(getMethodCache_cv(c));
  });

  print(+cachesMade);
}

Author comment

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: 141 / 242
Version history: 9 change(s)
Referenced in: [show references]