Created
July 30, 2014 11:34
-
-
Save chrisvest/0427ecb96dab5703c1da to your computer and use it in GitHub Desktop.
The cost of finalizer methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.openjdk.jmh.annotations.Benchmark; | |
public class Finalizer | |
{ | |
private static class ObjectWithFinalizer | |
{ | |
@Override | |
protected void finalize() throws Throwable | |
{ | |
super.finalize(); | |
} | |
} | |
@Benchmark | |
public Object createNormal() | |
{ | |
return new Object(); | |
} | |
@Benchmark | |
public ObjectWithFinalizer createWithFinalizer() | |
{ | |
return new ObjectWithFinalizer(); | |
} | |
} | |
/* | |
$ java -version | |
java version "1.7.0_51" | |
Java(TM) SE Runtime Environment (build 1.7.0_51-b13) | |
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode) | |
$ java -jar target/benchmarks.jar '.*Finalizer.*' -prof gc -f 5 -wi 5 -i 10 | |
Benchmark Mode Samples Score Score error Units | |
o.n.p.Finalizer.createNormal thrpt 50 303235578.567 1744302.614 ops/s | |
o.n.p.Finalizer.createNormal:@gc.count thrpt 50 21.080 1.428 counts | |
o.n.p.Finalizer.createNormal:@gc.time thrpt 50 0.849 0.057 % | |
o.n.p.Finalizer.createWithFinalizer thrpt 50 2216920.119 545429.448 ops/s | |
o.n.p.Finalizer.createWithFinalizer:@gc.count thrpt 50 1.400 0.245 counts | |
o.n.p.Finalizer.createWithFinalizer:@gc.time thrpt 50 66.631 7.961 % | |
$ java -version | |
java version "1.8.0" | |
Java(TM) SE Runtime Environment (build 1.8.0-b132) | |
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode) | |
$ java -jar target/benchmarks.jar '.*Finalizer.*' -prof gc -f 5 -wi 5 -i 10 | |
Benchmark Mode Samples Score Score error Units | |
o.n.p.Finalizer.createNormal thrpt 50 303414952.892 2684136.060 ops/s | |
o.n.p.Finalizer.createNormal:@gc.count thrpt 50 24.700 0.896 counts | |
o.n.p.Finalizer.createNormal:@gc.time thrpt 50 0.887 0.031 % | |
o.n.p.Finalizer.createWithFinalizer thrpt 50 707795.468 345959.174 ops/s | |
o.n.p.Finalizer.createWithFinalizer:@gc.count thrpt 50 5.420 2.400 counts | |
o.n.p.Finalizer.createWithFinalizer:@gc.time thrpt 50 84.080 6.941 % | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment