Skip to content

Commit

Permalink
Improve benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
P3ridot committed Jul 18, 2023
1 parent e60fd6b commit 0683bef
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

/* JDK17 (I5-8600K OC 4.5 Ghz, 32GB RAM 3200Mhz, Windows 10)
Benchmark Mode Cnt Score Error Units
InstanceConstructionBenchmark.direct thrpt 10 1781363.7465913.192 ops/ms
InstanceConstructionBenchmark.injected thrpt 10 1691.49627.704 ops/ms
InstanceConstructionBenchmark.injectedStatic thrpt 10 2685.87248.589 ops/ms
InstanceConstructionBenchmark.reflection thrpt 10 102089.7544540.710 ops/ms
InstanceConstructionBenchmark.direct thrpt 10 1722222.040261518.655 ops/ms
InstanceConstructionBenchmark.injected thrpt 10 1678.588 11.786 ops/ms
InstanceConstructionBenchmark.injectedStatic thrpt 10 2678.599 15.572 ops/ms
InstanceConstructionBenchmark.reflection thrpt 10 104147.946 336.587 ops/ms
*/
@Fork(value = 1)
@Warmup(iterations = 10, time = 2)
Expand All @@ -45,7 +45,7 @@ private static class EntityData {
private final int coins;
private final float health;

private EntityData(int coins, float health) {
public EntityData(int coins, float health) {
this.coins = coins;
this.health = health;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.panda_lang.utilities.inject;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
Expand All @@ -19,10 +20,10 @@

/* JDK17 (I5-8600K OC 4.5 Ghz, 32GB RAM 3200Mhz, Windows 10)
Benchmark Mode Cnt Score Error Units
InstanceConstructionWithFieldsBenchmark.direct thrpt 10 1783887.5234646.745 ops/ms
InstanceConstructionWithFieldsBenchmark.injected thrpt 10 1302.9718.086 ops/ms
InstanceConstructionWithFieldsBenchmark.injectedStatic thrpt 10 1697.86910.716 ops/ms
InstanceConstructionWithFieldsBenchmark.reflection thrpt 10 15222.960133.865 ops/ms
InstanceConstructionWithFieldsBenchmark.direct thrpt 10 1786947.021 9127.717 ops/ms
InstanceConstructionWithFieldsBenchmark.injected thrpt 10 1328.763 4.493 ops/ms
InstanceConstructionWithFieldsBenchmark.injectedStatic thrpt 10 1707.824 16.935 ops/ms
InstanceConstructionWithFieldsBenchmark.reflection thrpt 10 25232.337 48.927 ops/ms
*/
@Fork(value = 1)
@Warmup(iterations = 10, time = 2)
Expand All @@ -36,9 +37,9 @@ private static class Entity {
private final String name;

@Inject
public EntityData data;
private EntityData data;
@Inject
public EntityStorage storage;
private EntityStorage storage;

public Entity(int id, String name) {
this.name = name;
Expand Down Expand Up @@ -79,8 +80,15 @@ public void direct(DIState state) {
@Benchmark
public void reflection(DIState state) throws Throwable {
Entity object = state.constructor.newInstance(123456789, "PandaIsCool");
Entity.class.getField("data").set(object, state.entityDataSupplier.get());
Entity.class.getField("storage").set(object, state.entityStorage);
state.constructor.setAccessible(true);

Field dataField = Entity.class.getDeclaredField("data");
dataField.setAccessible(true);
dataField.set(object, state.entityDataSupplier.get());

Field storageField = Entity.class.getDeclaredField("storage");
storageField.setAccessible(true);
storageField.set(object, state.entityStorage);
}

@Benchmark
Expand Down

0 comments on commit 0683bef

Please sign in to comment.