You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "iamhucong (via GitHub)" <gi...@apache.org> on 2023/09/27 10:38:31 UTC

[GitHub] [shardingsphere] iamhucong opened a new issue, #28602: Consider replacing the low-performance TreeMap with a more efficient data structure that supports case-insensitive ordering.

iamhucong opened a new issue, #28602:
URL: https://github.com/apache/shardingsphere/issues/28602

   Based on the JMH test, the CaseInsensitiveMap in Apache Commons Collections demonstrates higher performance.
   ## JMH test code
   ```java
   @BenchmarkMode(Mode.AverageTime)
   @OutputTimeUnit(TimeUnit.NANOSECONDS)
   @Warmup(iterations = 5, time = 1)
   @Measurement(iterations = 5, time = 1)
   @Fork(3)
   @State(Scope.Benchmark)
   public class CaseInsensitiveMapBenchmarkRunner {
       public static void main(String[] args) throws IOException {
           org.openjdk.jmh.Main.main(args);
       }
       
       private Map<String, String> hashmap;
       private Map<String, String> caseInsensitiveMap;
       private Map<String, String> treeMap;
       private Collection<String> params;
       @Param({"10","100","1000","10000","100000"})
       private int size;
       
       @Setup(Level.Trial)
       public void setUp() {
           hashmap = new HashMap<>();
           caseInsensitiveMap = new CaseInsensitiveMap<>();
           treeMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
           params = new ArrayList<>();
           Instancio.of(String.class).stream().limit(size).forEach(s -> {
               hashmap.put(s.toLowerCase(), s);
               caseInsensitiveMap.put(s, s);
               treeMap.put(s, s);
               params.add(s);
           });
       }
       
       @Benchmark
       public void hashmap(Blackhole blackhole) {
           params.forEach(s -> blackhole.consume(hashmap.get(s.toLowerCase())));
       }
       
       @Benchmark
       public void caseInsensitiveMap(Blackhole blackhole) {
           params.forEach(s -> blackhole.consume(caseInsensitiveMap.get(s)));
       }
       
       @Benchmark
       public void treemap(Blackhole blackhole) {
           params.forEach(s -> blackhole.consume(treeMap.get(s)));
       }
       
   }
   ``` 
   <img width="1527" alt="image" src="https://github.com/apache/shardingsphere/assets/20391901/b91bdbca-db15-4bca-83c1-ef01b7a2a22c">
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Consider replacing the low-performance TreeMap with a more efficient data structure that supports case-insensitive ordering. [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu closed issue #28602: Consider replacing the low-performance TreeMap with a more efficient data structure that supports case-insensitive ordering.
URL: https://github.com/apache/shardingsphere/issues/28602


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org