Home / Class/ DefaultAttributeMapBenchmark Class — netty Architecture

DefaultAttributeMapBenchmark Class — netty Architecture

Architecture documentation for the DefaultAttributeMapBenchmark class in DefaultAttributeMapBenchmark.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  4d58d226_11dd_ffeb_a5a9_d53d9ae0abd8["DefaultAttributeMapBenchmark"]
  6515dff1_2582_cebe_c6ad_684b68c1d408["DefaultAttributeMapBenchmark.java"]
  4d58d226_11dd_ffeb_a5a9_d53d9ae0abd8 -->|defined in| 6515dff1_2582_cebe_c6ad_684b68c1d408
  fe68cde0_48d9_20d3_1a4c_d46e4e0c2944["init()"]
  4d58d226_11dd_ffeb_a5a9_d53d9ae0abd8 -->|method| fe68cde0_48d9_20d3_1a4c_d46e4e0c2944
  1443acc3_fae8_9932_da15_0cff3f2226f7["nextAttributeIdentityHashMap()"]
  4d58d226_11dd_ffeb_a5a9_d53d9ae0abd8 -->|method| 1443acc3_fae8_9932_da15_0cff3f2226f7
  8a23bfac_6bab_07d9_2a84_439e94d247b0["hasAttributeIdentityHashMap()"]
  4d58d226_11dd_ffeb_a5a9_d53d9ae0abd8 -->|method| 8a23bfac_6bab_07d9_2a84_439e94d247b0
  192460d4_8e86_5270_826c_f33f48ae7cda["mixedAttributeIdentityHashMap()"]
  4d58d226_11dd_ffeb_a5a9_d53d9ae0abd8 -->|method| 192460d4_8e86_5270_826c_f33f48ae7cda
  ce6ea3ed_9be9_4798_acce_6a4576db7894["nextAttributeAttributeMap()"]
  4d58d226_11dd_ffeb_a5a9_d53d9ae0abd8 -->|method| ce6ea3ed_9be9_4798_acce_6a4576db7894
  cd61fd44_2b27_d59d_2eaf_7dd0a4726f99["nextHasAttributeAttributeMap()"]
  4d58d226_11dd_ffeb_a5a9_d53d9ae0abd8 -->|method| cd61fd44_2b27_d59d_2eaf_7dd0a4726f99
  5405260e_6f97_1f5d_1c07_c29a2a7edf9a["mixedAttributeAttributeMap()"]
  4d58d226_11dd_ffeb_a5a9_d53d9ae0abd8 -->|method| 5405260e_6f97_1f5d_1c07_c29a2a7edf9a

Relationship Graph

Source Code

microbench/src/main/java/io/netty/util/DefaultAttributeMapBenchmark.java lines 32–135

@Warmup(iterations = 5, time = 1)
@Measurement(iterations = 5, time = 1)
@State(Scope.Benchmark)
public class DefaultAttributeMapBenchmark extends AbstractMicrobenchmark {

    @Param({ "8", "32", "128" })
    private int keyCount;
    private AttributeKey<Integer>[] keys;
    private IdentityHashMap<AttributeKey<Integer>, Attribute<Integer>> identityHashMap;
    private DefaultAttributeMap attributes;

    @State(Scope.Thread)
    public static class KeySequence {

        long nextKey;

        @Setup(Level.Iteration)
        public void reset() {
            nextKey = 0;
        }

        public long next() {
            return nextKey++;
        }
    }

    @Setup
    public void init() {
        if (Integer.bitCount(keyCount) != 1) {
            throw new AssertionError("keyCount should cbe a power of 2");
        }
        attributes = new DefaultAttributeMap();
        keys = new AttributeKey[keyCount];
        identityHashMap = new IdentityHashMap<AttributeKey<Integer>, Attribute<Integer>>(keyCount);
        for (int i = 0; i < keyCount; i++) {
            final AttributeKey<Integer> key = AttributeKey.valueOf(Integer.toString(i));
            keys[i] = key;
            final Attribute<Integer> attribute = attributes.attr(key);
            identityHashMap.put(key, attribute);
        }
    }

    @Benchmark
    @Threads(3)
    public Attribute<Integer> nextAttributeIdentityHashMap(KeySequence sequence) {
        long next = sequence.next();
        AttributeKey<Integer>[] keys = this.keys;
        AttributeKey<Integer> key = keys[(int) (next & keys.length - 1)];
        return identityHashMap.get(key);
    }

    @Benchmark
    @Threads(3)
    public boolean hasAttributeIdentityHashMap(KeySequence sequence) {
        long next = sequence.next();
        AttributeKey<Integer>[] keys = this.keys;
        AttributeKey<Integer> key = keys[(int) (next & keys.length - 1)];
        return identityHashMap.containsKey(key);
    }

    @Benchmark
    @Threads(3)
    public void mixedAttributeIdentityHashMap(KeySequence sequence, Blackhole hole) {
        long next = sequence.next();
        AttributeKey<Integer>[] keys = this.keys;
        AttributeKey<Integer> key = keys[(int) (next & keys.length - 1)];
        if (next % 2 == 0) {
            hole.consume(identityHashMap.get(key));
        } else {
            hole.consume(identityHashMap.containsKey(key));
        }
    }

    @Benchmark
    @Threads(3)
    public Attribute<Integer> nextAttributeAttributeMap(KeySequence sequence) {
        long next = sequence.next();
        AttributeKey<Integer>[] keys = this.keys;
        AttributeKey<Integer> key = keys[(int) (next & keys.length - 1)];
        return attributes.attr(key);
    }

Frequently Asked Questions

What is the DefaultAttributeMapBenchmark class?
DefaultAttributeMapBenchmark is a class in the netty codebase, defined in microbench/src/main/java/io/netty/util/DefaultAttributeMapBenchmark.java.
Where is DefaultAttributeMapBenchmark defined?
DefaultAttributeMapBenchmark is defined in microbench/src/main/java/io/netty/util/DefaultAttributeMapBenchmark.java at line 32.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free