tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] otaviojava opened a new pull request #1001: uses the directly field instead of getter method
Date Wed, 21 Nov 2018 13:39:49 GMT
otaviojava opened a new pull request #1001: uses the directly field instead of getter method
URL: https://github.com/apache/tinkerpop/pull/1001
 
 
   Hello everyone, I still studying the code to help more in the project, then I found a small
performance improvement. That is access the field directly instead of using the getter setter.
   
   
   ```java
   @Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
   @Measurement(iterations = 20, time = 1, timeUnit = TimeUnit.SECONDS)
   @Fork(3)
   @BenchmarkMode(Mode.AverageTime)
   @OutputTimeUnit(TimeUnit.NANOSECONDS)
   @State(Scope.Thread)
   public class Benchmark {
   
       private final Person person = new Person();
   
       @Setup
       public void setup() {
       }
   
       @Benchmark
       public String fieldDirectly() {
           return person.name;
       }
   
       @Benchmark
       public String getMethod() {
           return person.getName();
       }
   
       private class Person {
   
           private final String name = "ada";
   
           public String getName() {
               return name;
           }
       }
   
   }
   ```
   
   * Benchmark.fieldDirectly  avgt   60  2,768 ± 0,011  ns/op 
   * Benchmark.getMethod      avgt   60  3,010 ± 0,052  ns/op (around 12% slower)
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message