package net.openhft.chronicle.queue.bench;

import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.bytes.BytesStore;
import net.openhft.chronicle.core.OS;
import net.openhft.chronicle.core.io.BackgroundResourceReleaser;
import net.openhft.chronicle.core.io.IOTools;
import net.openhft.chronicle.core.util.Time;
import net.openhft.chronicle.queue.ChronicleQueue;
import net.openhft.chronicle.queue.ExcerptAppender;
import net.openhft.chronicle.queue.ExcerptTailer;
import net.openhft.chronicle.queue.RollCycles;
import net.openhft.chronicle.wire.DocumentContext;

/*
ARMv7 Processor rev 10 (v7l), Quad 1 GHz.
Writing 36,699,566 messages took 20.297 seconds, at a rate of 1,808,092 per second
Reading 36,699,566 messages took 28.283 seconds, at a rate of 1,297,576 per second
 */
public class ThroughputPerfMain {
    private static final int time = Integer.getInteger("time", 20);
    private static final int size = Integer.getInteger("size", 40);
    private static final String path = System.getProperty("path", OS.TMP);
    private static final long blockSize = Long.getLong("blockSize", OS.is64Bit() ? 4L << 30 : 256L << 20);

    private static BytesStore nbs;

    public static void main(String[] args) {
        String base = path + "/delete-" + Time.uniqueId() + ".me";
        long start = System.nanoTime();
        long count = 0;
        nbs = BytesStore.nativeStoreWithFixedCapacity(size);

        try (ChronicleQueue q = ChronicleQueue.singleBuilder(base)
                .rollCycle(RollCycles.LARGE_HOURLY_XSPARSE)
                .blockSize(blockSize)
                .build()) {

            ExcerptAppender appender = q.acquireAppender();
            do {
                try (DocumentContext dc = appender.writingDocument()) {
                    dc.wire().bytes().write(nbs);
                }
                count++;
            } while (start + time * 1e9 > System.nanoTime());
        }

        nbs.releaseLast();
        long mid = System.nanoTime();
        long time1 = mid - start;

        Bytes<?> bytes = Bytes.allocateElasticDirect(64);
        try (ChronicleQueue q = ChronicleQueue.singleBuilder(base)
                .rollCycle(RollCycles.LARGE_HOURLY_XSPARSE)
                .blockSize(blockSize)
                .build()) {
            ExcerptTailer tailer = q.createTailer();
            for (long i = 0; i < count; i++) {
                try (DocumentContext dc = tailer.readingDocument()) {
                    bytes.clear();
                    bytes.write(dc.wire().bytes());
                }
            }
        }
        bytes.releaseLast();
        long end = System.nanoTime();
        long time2 = end - mid;

        System.out.printf("Writing %,d messages took %.3f seconds, at a rate of %,d per second%n",
                count, time1 / 1e9, (long) (1e9 * count / time1));
        System.out.printf("Reading %,d messages took %.3f seconds, at a rate of %,d per second%n",
                count, time2 / 1e9, (long) (1e9 * count / time2));

        BackgroundResourceReleaser.releasePendingResources();
        System.gc(); // make sure its cleaned up for windows to delete.
        IOTools.deleteDirWithFiles(base, 2);
    }
}

@@ -579,68 +579,126 @@
 %0A/*%0A
-ARMv7 Processor rev 10 (v7l), Quad 1 GHz.%0AWriting 36,699,566
+Ryzen 9 5950X with Corsair MP600 PRO XT%0A-Dtime=30 -Dsize=1000000 -Dpath=/data/tmp - DblockSizeMB=524288%0AWriting 44,749
  mes
@@ -712,14 +712,14 @@
 ook 
-20.297
+30.001
  sec
@@ -743,15 +743,11 @@
 f 1,
-808,092
+491
  per
@@ -766,18 +766,14 @@
 ing 
-36,699,566
+44,749
  mes
@@ -787,14 +787,14 @@
 ook 
-28.283
+14.461
  sec
@@ -816,17 +816,13 @@
  of 
-1,297,576
+3,094
  per
@@ -896,20 +896,20 @@
 nal int 
-time
+TIME
  = Integ
@@ -930,17 +930,17 @@
 %22time%22, 
-2
+3
 0);%0A    
@@ -964,20 +964,20 @@
 nal int 
-size
+SIZE
  = Integ
@@ -1035,20 +1035,20 @@
  String 
-path
+PATH
  = Syste
@@ -1117,16 +1117,18 @@
 lockSize
+MB
  = Long.
@@ -1149,16 +1149,18 @@
 Size
+MB
 %22, OS.is
 64Bi
@@ -1159,33 +1159,49 @@
 S.is
-64Bit
+SparseFileSupported
 () ? 
-4
+512
 L %3C%3C 
-3
+1
 0 : 256L
  %3C%3C 
@@ -1200,14 +1200,8 @@
 256L
- %3C%3C 20
 );%0A%0A
@@ -1303,20 +1303,20 @@
  base = 
-path
+PATH
  + %22/del
@@ -1466,20 +1466,20 @@
 apacity(
-size
+SIZE
 );%0A%0A    
@@ -1629,32 +1629,40 @@
 ckSize(blockSize
+MB %3C%3C 20
 )%0A              
@@ -1947,20 +1947,20 @@
 start + 
-time
+TIME
  * 1e9 %3E
@@ -2312,16 +2312,24 @@
 lockSize
+MB %3C%3C 20
 )%0A      
@@ -2749,16 +2749,185 @@
 - mid;%0A%0A
+        System.out.println(%22-Dtime=%22 + TIME +%0A                %22 -Dsize=%22 + SIZE +%0A                %22 -Dpath=%22 + PATH +%0A                %22 - DblockSizeMB=%22 + blockSizeMB);%0A
         

Add logging of parameters