Repository: apache/kafka
File: jmh-benchmarks/src/main/java/org/apache/kafka/jmh/log/TestLinearWriteSpeed.java (Java)

Code before:
                double elapsedSecs = (start - lastReport) / (1000.0 * 1000.0 * 1000.0);
                double mb = written / (1024.0 * 1024.0);
                System.out.printf("%10.3f\t%10.3f\t%10.3f%n", mb / elapsedSecs, (totalLatency / (double) count) / (1000.0 * 1000.0), maxLatency / (1000.0 * 1000.0));
                lastReport = start;
                written = 0;
                maxLatency = 0L;
                totalLatency = 0L;
            } else if (written > maxThroughputBytes * (reportingInterval / 1000.0)) {
                long lastReportMs = lastReport / (1000 * 1000);
                long now = System.nanoTime() / (1000 * 1000);
                long sleepMs = lastReportMs + reportingInterval - now;
                if (sleepMs > 0)
                    Thread.sleep(sleepMs);
            }
        }
        double elapsedSecs = (System.nanoTime() - beginTest) / (1000.0 * 1000.0 * 1000.0);
        System.out.println((bytesToWrite / (1024.0 * 1024.0 * elapsedSecs)) + " MB per sec");
        scheduler.shutdown();
        for (Writable writable : writables) {
            writable.close();
        }
    }

    private static void setupCompression(CompressionType compressionType,
                                         Compression.Builder<? extends Compression> compressionBuilder,
                                         Integer compressionLevel) {
        switch (compressionType) {
            case GZIP:
                ((GzipCompression.Builder) compressionBuilder)
                    .level(compressionLevel != null ? compressionLevel : CompressionType.GZIP.defaultLevel());
                break;
            case LZ4:
                ((Lz4Compression.Builder) compressionBuilder)
                    .level(compressionLevel != null ? compressionLevel : CompressionType.LZ4.defaultLevel());
                break;
            case ZSTD:
                ((ZstdCompression.Builder) compressionBuilder)
                    .level(compressionLevel != null ? compressionLevel : CompressionType.ZSTD.defaultLevel());
                break;
            default:
                break;
        }
    }

    interface Writable {
        int write() throws IOException;

        void close() throws IOException;
    }

    static class MmapWritable implements Writable {

Review comment (suggestion):
Perhaps we could call `setupCompression` only if `compressionLevel` is defined. WDYT?

```java
if (compressionLevel != null) setupCompression(compressionType, compressionBuilder, compressionLevel);
```

Code after:
                double elapsedSecs = (start - lastReport) / (1000.0 * 1000.0 * 1000.0);
                double mb = written / (1024.0 * 1024.0);
                System.out.printf("%10.3f\t%10.3f\t%10.3f%n", mb / elapsedSecs, (totalLatency / (double) count) / (1000.0 * 1000.0), maxLatency / (1000.0 * 1000.0));
                lastReport = start;
                written = 0;
                maxLatency = 0L;
                totalLatency = 0L;
            } else if (written > maxThroughputBytes * (reportingInterval / 1000.0)) {
                long lastReportMs = lastReport / (1000 * 1000);
                long now = System.nanoTime() / (1000 * 1000);
                long sleepMs = lastReportMs + reportingInterval - now;
                if (sleepMs > 0)
                    Thread.sleep(sleepMs);
            }
        }
        double elapsedSecs = (System.nanoTime() - beginTest) / (1000.0 * 1000.0 * 1000.0);
        System.out.println((bytesToWrite / (1024.0 * 1024.0 * elapsedSecs)) + " MB per sec");
        scheduler.shutdown();
        for (Writable writable : writables) {
            writable.close();
        }
    }

    private static void setupCompression(CompressionType compressionType,
                                         Compression.Builder<? extends Compression> compressionBuilder,
                                         Integer compressionLevel) {
        switch (compressionType) {
            case GZIP:
                ((GzipCompression.Builder) compressionBuilder).level(compressionLevel);
                break;
            case LZ4:
                ((Lz4Compression.Builder) compressionBuilder).level(compressionLevel);
                break;
            case ZSTD:
                ((ZstdCompression.Builder) compressionBuilder).level(compressionLevel);
                break;
            default:
                break;
        }
    }

    interface Writable {
        int write() throws IOException;

        void close() throws IOException;
    }

    static class MmapWritable implements Writable {
        File file;
        ByteBuffer content;
        RandomAccessFile raf;