ChineseTony commented on PR #7869:
URL: https://github.com/apache/rocketmq/pull/7869#issuecomment-1970299363

   ```java
   import org.openjdk.jmh.annotations.Benchmark;
   import org.openjdk.jmh.annotations.BenchmarkMode;
   import org.openjdk.jmh.annotations.Fork;
   import org.openjdk.jmh.annotations.Measurement;
   import org.openjdk.jmh.annotations.Mode;
   import org.openjdk.jmh.annotations.OutputTimeUnit;
   import org.openjdk.jmh.annotations.Scope;
   import org.openjdk.jmh.annotations.Setup;
   import org.openjdk.jmh.annotations.State;
   import org.openjdk.jmh.annotations.Threads;
   import org.openjdk.jmh.annotations.Warmup;
   
   import java.util.HashMap;
   import java.util.Map;
   import java.util.concurrent.TimeUnit;
   
   @BenchmarkMode(Mode.Throughput)
   @Warmup(iterations = 3, time = 1)
   @Measurement(iterations = 5, time = 3)
   @Fork(1)
   @State(value = Scope.Benchmark)
   @OutputTimeUnit(TimeUnit.SECONDS)
   
   public class MapUtil {
       private Map<String, String> map = new HashMap<>();
   
       @Setup
       public void setup() {
           for (int i = 0; i < 8000; i++) {
               map.put(i + "", i + "");
           }
       }
   
       @Benchmark
       @Threads(8)
       public void keySetMap() {
           keySet();
       }
   
       @Benchmark
       @Threads(8)
       public void entrySetMap() {
           entrySet();
       }
   
       private void entrySet() {
           for (Map.Entry<String, String> entry : map.entrySet()) {
               entry.getValue();
           }
       }
   
       private void keySet() {
           for (String key : map.keySet()) {
               map.get(key);
           }
       }
   }
   ```
   
   Benchmark             Mode  Cnt       Score        Error  Units
   MapUtil.entrySetMap  thrpt    5  172067.111 ± 452324.484  ops/s
   MapUtil.keySetMap    thrpt    5  109211.325 ±  41925.022  ops/s


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to