SAP / cf-java-logging-support

The Java Logging Support for Cloud Foundry supports the creation of structured log messages and the collection of request metrics
Apache License 2.0
77 stars 48 forks source link

Remove StringBuilder in Logback TimestampConverter #97

Closed rahuldeepattri closed 3 years ago

rahuldeepattri commented 3 years ago

Fix for #90

The benchmark done using JMH show performance improvement.

    @Benchmark
    public String benchmarkStringBuilder() {
        Instant now = Instant.now();
        long timestamp = now.getEpochSecond() * 1_000_000_000L + now.getNano();

        StringBuilder appendTo = new StringBuilder();
        appendTo.append(timestamp);
        return appendTo.toString();
    }

    @Benchmark
    public String benchmarkString() {
        Instant now = Instant.now();
        long timestamp = now.getEpochSecond() * 1_000_000_000L + now.getNano();

        return String.valueOf(timestamp);
    }

Result:

Benchmark                                                           Mode     Cnt   Score   Error   Units
Comparison.benchmarkString                                         thrpt     100   2.130 ± 0.052  ops/ms
Comparison.benchmarkStringBuilder                                  thrpt     100   1.801 ± 0.028  ops/ms
Comparison.benchmarkString                                          avgt     100   0.469 ± 0.011   ms/op
Comparison.benchmarkStringBuilder                                   avgt     100   0.862 ± 0.038   ms/op
Comparison.benchmarkString                                            ss     100   0.591 ± 0.095   ms/op
Comparison.benchmarkStringBuilder                                     ss     100   0.966 ± 0.118   ms/op
CLAassistant commented 3 years ago

CLA assistant check
All committers have signed the CLA.

rahuldeepattri commented 3 years ago

Hi @KarstenSchnitter, sorry my mistake. Fixed the indentation.