Home / Class/ IsValidIpV4Benchmark Class — netty Architecture

IsValidIpV4Benchmark Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  03a72f97_be98_f809_61f6_bc171ba876a8["IsValidIpV4Benchmark"]
  b663b83e_b88b_c2e2_8537_fe9937a8030b["IsValidIpV4Benchmark.java"]
  03a72f97_be98_f809_61f6_bc171ba876a8 -->|defined in| b663b83e_b88b_c2e2_8537_fe9937a8030b
  da6dff0f_872c_87bd_44ec_6f3d60def47e["isValidIpV4AddressOld()"]
  03a72f97_be98_f809_61f6_bc171ba876a8 -->|method| da6dff0f_872c_87bd_44ec_6f3d60def47e
  0a3dd286_d12b_f917_3833_df253a424f06["isValidIpV4AddressNew()"]
  03a72f97_be98_f809_61f6_bc171ba876a8 -->|method| 0a3dd286_d12b_f917_3833_df253a424f06

Relationship Graph

Source Code

microbench/src/main/java/io/netty/microbenchmark/common/IsValidIpV4Benchmark.java lines 29–91

@Threads(1)
@Warmup(iterations = 3)
@Measurement(iterations = 3)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public class IsValidIpV4Benchmark extends AbstractMicrobenchmark {

    @Param({ "127.0.0.1", "255.255.255.255", "1.1.1.1", "127.0.0.256", "127.0.0.1.1", "127.0.0", "[2001::1]" })
    private String ip;

    public static boolean isValidIpV4AddressOld(String value) {

        int periods = 0;
        int i;
        int length = value.length();

        if (length > 15) {
            return false;
        }
        char c;
        StringBuilder word = new StringBuilder();
        for (i = 0; i < length; i++) {
            c = value.charAt(i);
            if (c == '.') {
                periods++;
                if (periods > 3) {
                    return false;
                }
                if (word.length() == 0) {
                    return false;
                }
                if (Integer.parseInt(word.toString()) > 255) {
                    return false;
                }
                word.delete(0, word.length());
            } else if (!Character.isDigit(c)) {
                return false;
            } else {
                if (word.length() > 2) {
                    return false;
                }
                word.append(c);
            }
        }

        if (word.length() == 0 || Integer.parseInt(word.toString()) > 255) {
            return false;
        }

        return periods == 3;
    }

    // Tests

    @Benchmark
    public boolean isValidIpV4AddressOld() {
        return isValidIpV4AddressOld(ip);
    }

    @Benchmark
    public boolean isValidIpV4AddressNew() {
        return NetUtil.isValidIpV4Address(ip);
    }
}

Frequently Asked Questions

What is the IsValidIpV4Benchmark class?
IsValidIpV4Benchmark is a class in the netty codebase, defined in microbench/src/main/java/io/netty/microbenchmark/common/IsValidIpV4Benchmark.java.
Where is IsValidIpV4Benchmark defined?
IsValidIpV4Benchmark is defined in microbench/src/main/java/io/netty/microbenchmark/common/IsValidIpV4Benchmark.java at line 29.

Analyze Your Own Codebase

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

Try Supermodel Free