mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-30 02:09:59 +07:00
`MultiRoutingFsPath` is marked as package-private to prevent its creation in different classloaders.
The benchmark that proves that `instanceof` is much faster than a hash-table goes below. Even though it's obvious that `instanceof` is faster, the benchmark shows how much it is faster.
```java
@State(Scope.Benchmark)
public class InstanceofCacheBenchmark {
private static final Map<Class<?>, Boolean> ourCache = Collections.synchronizedMap(new WeakHashMap<>());
private final Object targetObject;
public InstanceofCacheBenchmark() {
targetObject = this;
ourCache.put(getClass(), true);
}
@Benchmark
public void measureInstanceof() {
boolean ignored = targetObject instanceof InstanceofCacheBenchmark;
}
@Benchmark
public void measureCache() {
boolean ignored = ourCache.get(targetObject.getClass());
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(InstanceofCacheBenchmark.class.getSimpleName())
.threads(1)
.forks(0)
.build();
new Runner(opt).run();
}
}
```
On i9-12900 on Windows 11:
```
Benchmark Mode Cnt Score Error Units
InstanceofCacheBenchmark.measureCache thrpt 5 64987581.855 ± 111715.045 ops/s
InstanceofCacheBenchmark.measureInstanceof thrpt 5 2575306704.170 ± 1054801816.988 ops/s
```
GitOrigin-RevId: 2268e02a3e92bdb6dec8fc81efce8585a5eef2fd