From e0d0657e7b30b7856faa260893c8c2853ef8c1cc Mon Sep 17 00:00:00 2001 From: RePixelatedMC Date: Sat, 21 Oct 2023 15:25:55 +0200 Subject: [PATCH 01/10] thx coco --- build.gradle | 1 + .../iris/core/commands/CommandIris.java | 10 + .../iris/core/tools/IrisBenchmarking.java | 512 ++++++++++++++++++ 3 files changed, 523 insertions(+) create mode 100644 src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java diff --git a/build.gradle b/build.gradle index f30b24666..0d3f5027c 100644 --- a/build.gradle +++ b/build.gradle @@ -41,6 +41,7 @@ registerCustomOutputTask('Coco', 'D://mcsm/plugins') registerCustomOutputTask('Strange', 'D://Servers/1.17 Test Server/plugins') registerCustomOutputTask('Vatuu', 'D://Minecraft/Servers/1.19.4/plugins') registerCustomOutputTask('CrazyDev22', 'C://Users/Julian/Desktop/server/plugins') +registerCustomOutputTask('Pixel', 'C://Users/repix/Iris Dimension Engine/1.20.1 - Iris Coding/plugins') // ========================== UNIX ============================== registerCustomOutputTaskUnix('CyberpwnLT', '/Users/danielmills/development/server/plugins') registerCustomOutputTaskUnix('PsychoLT', '/Users/brianfopiano/Desktop/REMOTES/RemoteMinecraft/plugins') diff --git a/src/main/java/com/volmit/iris/core/commands/CommandIris.java b/src/main/java/com/volmit/iris/core/commands/CommandIris.java index 0f0f98eda..481d3b2dd 100644 --- a/src/main/java/com/volmit/iris/core/commands/CommandIris.java +++ b/src/main/java/com/volmit/iris/core/commands/CommandIris.java @@ -21,6 +21,7 @@ package com.volmit.iris.core.commands; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.service.StudioSVC; +import com.volmit.iris.core.tools.IrisBenchmarking; import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.object.IrisDimension; @@ -50,6 +51,7 @@ import java.io.File; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import static com.volmit.iris.core.tools.IrisBenchmarking.inProgress; import static com.volmit.iris.engine.safeguard.ServerBoot.multiverse; @Decree(name = "iris", aliases = {"ir", "irs"}, description = "Basic Command") @@ -139,6 +141,14 @@ public class CommandIris implements DecreeExecutor { public void version() { sender().sendMessage(C.GREEN + "Iris v" + Iris.instance.getDescription().getVersion() + " by Volmit Software"); } + @Decree(description = "Benchmark your server", origin = DecreeOrigin.CONSOLE) + public void benchmark() throws InterruptedException { + if(!inProgress) { + IrisBenchmarking.runBenchmark(); + } else { + Iris.info(C.RED + "Benchmark already is in progress."); + } + } @Decree(description = "Print world height information", origin = DecreeOrigin.PLAYER) public void height() { diff --git a/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java b/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java new file mode 100644 index 000000000..e861f6e06 --- /dev/null +++ b/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java @@ -0,0 +1,512 @@ +package com.volmit.iris.core.tools; + +import com.volmit.iris.Iris; +import com.volmit.iris.util.format.C; +import oshi.SystemInfo; +import oshi.hardware.CentralProcessor; +import oshi.hardware.GlobalMemory; +import oshi.hardware.HWDiskStore; +import oshi.software.os.OperatingSystem; + +import java.io.*; +import java.lang.management.ManagementFactory; +import java.lang.management.MemoryMXBean; +import java.lang.management.MemoryUsage; +import java.security.SecureRandom; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Base64; +import java.util.List; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.IntStream; +import java.util.zip.Deflater; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; + +import static com.google.common.math.LongMath.isPrime; + +public class IrisBenchmarking { + private static long startTime; + static double avgWriteSpeedMBps; + static double avgReadSpeedMBps; + static double highestWriteSpeedMBps; + static double highestReadSpeedMBps; + static double lowestWriteSpeedMBps; + static double lowestReadSpeedMBps; + static double calculateIntegerMath; + static double calculateFloatingPoint; + static double calculatePrimeNumbers; + static double calculateStringSorting; + static double calculateDataEncryption; + static double calculateDataCompression; + static String currentRunning = "None"; + static int BenchmarksCompleted = -1; + static int BenchmarksTotal = 6; + static int totalTasks = 10; + static int currentTasks = 0; + static double elapsedTimeNs; + public static boolean inProgress = false; + // Good enough for now. . . + + public static void runBenchmark() throws InterruptedException { + inProgress = true; + AtomicReference doneCalculateDiskSpeed = new AtomicReference<>((double) 0); + startBenchmarkTimer(); + Iris.info("Benchmark Started!"); + Iris.warn("Although it may seem momentarily paused, it's actively processing."); + Thread progressBarThread = new Thread(() -> { + try { + progressBar(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }); + progressBarThread.start(); + + // help + CompletableFuture future = CompletableFuture.runAsync(() -> { + doneCalculateDiskSpeed.set(roundToTwoDecimalPlaces(calculateDiskSpeed())); + }).thenRun(() -> { + BenchmarksCompleted++; + calculateIntegerMath = roundToTwoDecimalPlaces(calculateIntegerMath()); + }).thenRun(() -> { + BenchmarksCompleted++; + calculateFloatingPoint = roundToTwoDecimalPlaces(calculateFloatingPoint()); + }).thenRun(() -> { + BenchmarksCompleted++; + calculateStringSorting = roundToTwoDecimalPlaces(calculateStringSorting()); + }).thenRun(() -> { + BenchmarksCompleted++; + calculateDataEncryption = roundToTwoDecimalPlaces(calculateDataEncryption()); + }).thenRun(() -> { + BenchmarksCompleted++; + calculateDataCompression = roundToTwoDecimalPlaces(calculateDataCompression()); + }).thenRun(() -> { + BenchmarksCompleted++; + elapsedTimeNs = stopBenchmarkTimer(); + results(); + inProgress = false; + }); + + try { + future.get(); + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + } + } + + private static int previousCompleted = BenchmarksCompleted; + + // why just why + public static void progressBar() throws InterruptedException { + while (true) { + if (BenchmarksCompleted > previousCompleted) { + Iris.info("-----------------------------------------------------"); + Iris.info("Currently Running: " + C.BLUE + currentRunning); + // Iris.info("Tasks: " + "Current Tasks: " + C.BLUE + currentTasks + C.WHITE + " / " + "Total Tasks: " + C.BLUE + totalTasks); + Iris.info("Benchmarks Completed: " + C.BLUE + BenchmarksCompleted + C.WHITE + " / " +"Total: " + C.BLUE + BenchmarksTotal); + Iris.info("-----------------------------------------------------"); + + previousCompleted = BenchmarksCompleted; // Update the previous value + } + + if (BenchmarksCompleted == BenchmarksTotal) { + break; + } + Thread.sleep(10); + } + } + + + + public static void results() { + + SystemInfo systemInfo = new SystemInfo(); + GlobalMemory globalMemory = systemInfo.getHardware().getMemory(); + long totalMemoryMB = globalMemory.getTotal() / (1024 * 1024); + long availableMemoryMB = globalMemory.getAvailable() / (1024 * 1024); + long totalPageSize = globalMemory.getPageSize() / (1024 * 1024); + long usedMemoryMB = totalMemoryMB - availableMemoryMB; + MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); + + Iris.info("OS: " + serverOS()); + Iris.info("CPU Model: " + getCPUModel()); + Iris.info("CPU Score: " + "WIP"); + Iris.info("- Integer Math: " + calculateIntegerMath + " MOps/Sec"); + Iris.info("- Floating Point Math: " + calculateFloatingPoint + " MOps/Sec"); + Iris.info("- Find Prime Numbers: " + calculatePrimeNumbers + " Primes/Sec"); + Iris.info("- Random String Sorting: " + calculateStringSorting + " Thousand Strings/Sec"); + Iris.info("- Data Encryption: " + formatDouble(calculateDataEncryption) + " MBytes/Sec"); + Iris.info("- Data Compression: " + formatDouble(calculateDataCompression) + " MBytes/Sec"); + Iris.info("Disk Model: " + getDiskModel()); + Iris.info("- Average Write Speed: " + C.BLUE + formatDouble(avgWriteSpeedMBps) + " Mbp/Sec"); + Iris.info("- Average Read Speed: " + C.BLUE + formatDouble(avgReadSpeedMBps) + " Mbp/Sec"); + Iris.info("- Highest Write Speed: " + formatDouble(highestWriteSpeedMBps) + " Mbp/Sec"); + Iris.info("- Highest Read Speed: " + formatDouble(highestReadSpeedMBps) + " Mbp/Sec"); + Iris.info("- Lowest Write Speed: " + formatDouble(lowestWriteSpeedMBps) + " Mbp/Sec"); + Iris.info("- Lowest Read Speed: " + formatDouble(lowestReadSpeedMBps) + " Mbp/Sec"); + Iris.info("Ram Usage: "); + Iris.info("- Total Ram: " + totalMemoryMB + " MB"); + Iris.info("- Used Ram: " + usedMemoryMB + " MB"); + Iris.info("- Total Process Ram: " + C.BLUE + getMaxMemoryUsage() + " MB"); + Iris.info("- Total Paging Size: " + totalPageSize + " MB"); + Iris.info("Duration: " + roundToTwoDecimalPlaces(elapsedTimeNs) + " Seconds"); + } + public static long getMaxMemoryUsage() { + MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); + MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage(); + MemoryUsage nonHeapMemoryUsage = memoryMXBean.getNonHeapMemoryUsage(); + long maxHeapMemory = heapMemoryUsage.getMax(); + long maxNonHeapMemory = nonHeapMemoryUsage.getMax(); + long maxMemoryUsageMB = (maxHeapMemory + maxNonHeapMemory) / (1024 * 1024); + return maxMemoryUsageMB; + } + public static String serverOS() { + SystemInfo systemInfo = new SystemInfo(); + OperatingSystem os = systemInfo.getOperatingSystem(); + String osInfo = os.toString(); + return osInfo; + } + public static String getCPUModel() { + try { + SystemInfo systemInfo = new SystemInfo(); + CentralProcessor processor = systemInfo.getHardware().getProcessor(); + String cpuModel = processor.getProcessorIdentifier().getName(); + return cpuModel.isEmpty() ? "Unknown CPU Model" : cpuModel; + } catch (Exception e) { + e.printStackTrace(); + return "Unknown CPU Model"; + } + } + public static String getDiskModel() { + SystemInfo systemInfo = new SystemInfo(); + List diskStores = systemInfo.getHardware().getDiskStores(); + if (!diskStores.isEmpty()) { + HWDiskStore firstDisk = diskStores.get(0); + return firstDisk.getModel(); + } else { + return "Unknown Disk Model"; + } + } + private static String formatDouble(double value) { + return String.format("%.2f", value); + } + + private static void startBenchmarkTimer() { + startTime = System.nanoTime(); + } + + private static double stopBenchmarkTimer() { + long endTime = System.nanoTime(); + return (endTime - startTime) / 1_000_000_000.0; + } + public static double calculateCpuScore( + double calculateIntegerMath, + double calculateFloatingPoint, + double calculatePrimeNumbers, + double calculateStringSorting, + double calculateDataEncryption, + double calculateDataCompression + ) { + double weightIntegerMath = 1.0; + double weightFloatingPoint = 1.0; + double weightPrimeNumbers = 1.0; + double weightStringSorting = 1.0; + double weightDataEncryption = 1.0; + double weightDataCompression = 1.0; + + double invertedIntegerMath = 1.0 / calculateIntegerMath; + double invertedFloatingPoint = 1.0 / calculateFloatingPoint; + double invertedPrimeNumbers = 1.0 / calculatePrimeNumbers; + double invertedStringSorting = 1.0 / calculateStringSorting; + double invertedDataEncryption = 1.0 / calculateDataEncryption; + double invertedDataCompression = 1.0 / calculateDataCompression; + + double cpuScore = + ( + invertedIntegerMath * weightIntegerMath + + invertedFloatingPoint * weightFloatingPoint + + invertedPrimeNumbers * weightPrimeNumbers + + invertedStringSorting * weightStringSorting + + invertedDataEncryption * weightDataEncryption + + invertedDataCompression * weightDataCompression) / + (weightIntegerMath + weightFloatingPoint + weightPrimeNumbers + weightStringSorting + weightDataEncryption + weightDataCompression); + + return cpuScore; + } + private static double calculateIntegerMath() { + currentRunning = "calculateIntegerMath"; + final int numIterations = 1_000_000_000; + final int numRuns = 30; + double totalMopsPerSec = 0; + + for (int run = 0; run < numRuns; run++) { + long startTime = System.nanoTime(); + int result = 0; + + for (int i = 0; i < numIterations; i++) { + result += i * 2; + result -= i / 2; + result ^= i; + result <<= 1; + result >>= 1; + } + + long endTime = System.nanoTime(); + double elapsedSeconds = (endTime - startTime) / 1_000_000_000.0; + double mopsPerSec = (numIterations / elapsedSeconds) / 1_000_000.0; + + totalMopsPerSec += mopsPerSec; + } + + double averageMopsPerSec = totalMopsPerSec / numRuns; + return averageMopsPerSec; + } + private static double calculateFloatingPoint() { + long numIterations = 85_000_000; + int numRuns = 30; + int percent = 10; + double totalMopsPerSec = 0; + + for (int run = 0; run < numRuns; run++) { + percent = percent + 5; + double result = 0; + long startTime = System.nanoTime(); + + for (int i = 0; i < numIterations; i++) { + result += Math.sqrt(i) * Math.sin(i) / (i + 1); + } + + long endTime = System.nanoTime(); + double elapsedSeconds = (endTime - startTime) / 1_000_000_000.0; + double mopsPerSec = (numIterations / elapsedSeconds) / 1_000_000.0; + + totalMopsPerSec += mopsPerSec; + } + + double averageMopsPerSec = totalMopsPerSec / numRuns; + return averageMopsPerSec; + } + private static double calculatePrimeNumbers() { + currentRunning = "calculatePrimeNumbers"; + int primeCount; + long numIterations = 1_000_000; + int numRuns = 30; + double totalMopsPerSec = 0; + + for (int run = 0; run < numRuns; run++) { + primeCount = 0; + long startTime = System.nanoTime(); + + for (int num = 2; primeCount < numIterations; num++) { + if (isPrime(num)) { + primeCount++; + } + } + + long endTime = System.nanoTime(); + double elapsedSeconds = (endTime - startTime) / 1_000_000_000.0; + double mopsPerSec = (primeCount / elapsedSeconds) / 1_000_000.0; + + totalMopsPerSec += mopsPerSec; + } + + double averageMopsPerSec = totalMopsPerSec / numRuns; + return averageMopsPerSec; + } + private static double calculateStringSorting() { + currentRunning = "calculateStringSorting"; + int stringCount = 1_000_000; + int stringLength = 100; + int numRuns = 30; + double totalMopsPerSec = 0; + + for (int run = 0; run < numRuns; run++) { + List randomStrings = generateRandomStrings(stringCount, stringLength); + long startTime = System.nanoTime(); + randomStrings.sort(String::compareTo); + long endTime = System.nanoTime(); + + double elapsedSeconds = (endTime - startTime) / 1_000_000_000.0; + double mopsPerSec = (stringCount / elapsedSeconds) / 1_000.0; + + totalMopsPerSec += mopsPerSec; + } + + double averageMopsPerSec = totalMopsPerSec / numRuns; + return averageMopsPerSec; + } + public static double calculateDataEncryption() { + currentRunning = "calculateDataEncryption"; + int dataSizeMB = 100; + byte[] dataToEncrypt = generateRandomData(dataSizeMB * 1024 * 1024); + int numRuns = 20; + double totalMBytesPerSec = 0; + + for (int run = 0; run < numRuns; run++) { + long startTime = System.nanoTime(); + byte[] encryptedData = performEncryption(dataToEncrypt, 1); + + long endTime = System.nanoTime(); + double elapsedSeconds = (endTime - startTime) / 1_000_000_000.0; + double mbytesPerSec = (dataToEncrypt.length / (1024 * 1024.0)) / elapsedSeconds; + + totalMBytesPerSec += mbytesPerSec; + } + + double averageMBytesPerSec = totalMBytesPerSec / numRuns; + return averageMBytesPerSec; + } + private static byte[] performEncryption(byte[] data, int numRuns) { + byte[] key = "MyEncryptionKey".getBytes(); + byte[] result = Arrays.copyOf(data, data.length); + for (int run = 0; run < numRuns; run++) { + for (int i = 0; i < result.length; i++) { + result[i] ^= key[i % key.length]; + } + } + return result; + } + public static double calculateDataCompression() { + currentRunning = "calculateDataCompression"; + int dataSizeMB = 500; + byte[] dataToCompress = generateRandomData(dataSizeMB * 1024 * 1024); + long startTime = System.nanoTime(); + byte[] compressedData = performCompression(dataToCompress); + long endTime = System.nanoTime(); + + double elapsedSeconds = (endTime - startTime) / 1e9; + double mbytesPerSec = (compressedData.length / (1024.0 * 1024.0)) / elapsedSeconds; + + return mbytesPerSec; + } + private static byte[] performCompression(byte[] data) { + Deflater deflater = new Deflater(); + deflater.setInput(data); + deflater.finish(); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); + + byte[] buffer = new byte[1024]; + while (!deflater.finished()) { + int count = deflater.deflate(buffer); + outputStream.write(buffer, 0, count); + } + + deflater.end(); + return outputStream.toByteArray(); + } + private static List generateRandomStrings(int count, int length) { + SecureRandom random = new SecureRandom(); + List randomStrings = new ArrayList<>(); + + IntStream.range(0, count).forEach(i -> { + byte[] bytes = new byte[length]; + random.nextBytes(bytes); + randomStrings.add(Base64.getEncoder().encodeToString(bytes)); + }); + return randomStrings; + } + private static byte[] generateRandomData(int size) { + SecureRandom random = new SecureRandom(); + byte[] data = new byte[size]; + random.nextBytes(data); + return data; + } + private static double roundToTwoDecimalPlaces(double value) { + return Double.parseDouble(String.format("%.2f", value)); + } + private static double calculateCPUScore(long elapsedTimeNs) { + return 1.0 / (elapsedTimeNs / 1_000_000.0); + } + public static double calculateDiskSpeed() { + currentRunning = "calculateDiskSpeed"; + String filePath = "benchmark.dat"; + int numRuns = 10; + int fileSizeMB = 1000; + + double[] writeSpeeds = new double[numRuns]; + double[] readSpeeds = new double[numRuns]; + + for (int run = 0; run < numRuns; run++) { + long writeStartTime = System.nanoTime(); + deleteTestFile(filePath); + createTestFile(filePath, fileSizeMB); + long writeEndTime = System.nanoTime(); + + long readStartTime = System.nanoTime(); + readTestFile(filePath); + long readEndTime = System.nanoTime(); + + double writeSpeed = calculateDiskSpeedMBps(fileSizeMB, writeStartTime, writeEndTime); + double readSpeed = calculateDiskSpeedMBps(fileSizeMB, readStartTime, readEndTime); + + writeSpeeds[run] = writeSpeed; + readSpeeds[run] = readSpeed; + + if (run == 0) { + lowestWriteSpeedMBps = writeSpeed; + highestWriteSpeedMBps = writeSpeed; + lowestReadSpeedMBps = readSpeed; + highestReadSpeedMBps = readSpeed; + } else { + if (writeSpeed < lowestWriteSpeedMBps) { + lowestWriteSpeedMBps = writeSpeed; + } + if (writeSpeed > highestWriteSpeedMBps) { + highestWriteSpeedMBps = writeSpeed; + } + if (readSpeed < lowestReadSpeedMBps) { + lowestReadSpeedMBps = readSpeed; + } + if (readSpeed > highestReadSpeedMBps) { + highestReadSpeedMBps = readSpeed; + } + } + } + avgWriteSpeedMBps = calculateAverage(writeSpeeds); + avgReadSpeedMBps = calculateAverage(readSpeeds); + return 2; + } + public static void createTestFile(String filePath, int fileSizeMB) { + try { + File file = new File(filePath); + byte[] data = new byte[1024 * 1024]; + Arrays.fill(data, (byte) 0); + FileOutputStream fos = new FileOutputStream(file); + for (int i = 0; i < fileSizeMB; i++) { + fos.write(data); + } + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + public static void readTestFile(String filePath) { + try { + File file = new File(filePath); + FileInputStream fis = new FileInputStream(file); + byte[] buffer = new byte[1024]; + while (fis.read(buffer) != -1) { + } + fis.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + public static void deleteTestFile(String filePath) { + File file = new File(filePath); + file.delete(); + } + public static double calculateDiskSpeedMBps(int fileSizeMB, long startTime, long endTime) { + double elapsedSeconds = (endTime - startTime) / 1_000_000_000.0; + double writeSpeed = (fileSizeMB / elapsedSeconds); + return writeSpeed; + } + public static double calculateAverage(double[] values) { + double sum = 0; + for (double value : values) { + sum += value; + } + return sum / values.length; + } +} \ No newline at end of file From a883e43acbe25bf2c6f76added5ec6f643ec20ad Mon Sep 17 00:00:00 2001 From: RePixelatedMC Date: Sat, 21 Oct 2023 15:26:24 +0200 Subject: [PATCH 02/10] eh --- src/main/resources/plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 052267332..b2116b38f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -21,4 +21,4 @@ commands: iris: aliases: [ ir, irs ] api-version: '${apiversion}' -hotload-dependencies: false \ No newline at end of file +hotload-dependencies: falsec \ No newline at end of file From 01016d1b145fb06bb8263dad0876627672be762b Mon Sep 17 00:00:00 2001 From: RePixelatedMC Date: Sat, 21 Oct 2023 20:18:02 +0200 Subject: [PATCH 03/10] modes? --- .../iris/core/tools/IrisBenchmarking.java | 149 +++++++++++------- 1 file changed, 96 insertions(+), 53 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java b/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java index e861f6e06..8151a1d29 100644 --- a/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java +++ b/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java @@ -22,10 +22,14 @@ import java.util.stream.IntStream; import java.util.zip.Deflater; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import static com.google.common.math.LongMath.isPrime; public class IrisBenchmarking { + static String ServerOS; private static long startTime; static double avgWriteSpeedMBps; static double avgReadSpeedMBps; @@ -45,11 +49,14 @@ public class IrisBenchmarking { static int totalTasks = 10; static int currentTasks = 0; static double elapsedTimeNs; + static boolean WindowsDiskSpeed = false; public static boolean inProgress = false; // Good enough for now. . . public static void runBenchmark() throws InterruptedException { inProgress = true; + getServerOS(); + AtomicReference doneCalculateDiskSpeed = new AtomicReference<>((double) 0); startBenchmarkTimer(); Iris.info("Benchmark Started!"); @@ -65,7 +72,15 @@ public class IrisBenchmarking { // help CompletableFuture future = CompletableFuture.runAsync(() -> { - doneCalculateDiskSpeed.set(roundToTwoDecimalPlaces(calculateDiskSpeed())); + BenchmarksCompleted++; + if (ServerOS.contains("Windows") && isRunningAsAdmin()){ + WindowsDiskSpeed = true; + WindowsDiskSpeedTest(); + } else { + warningFallback(); + doneCalculateDiskSpeed.set(roundToTwoDecimalPlaces(calculateDiskSpeed())); + } + }).thenRun(() -> { BenchmarksCompleted++; calculateIntegerMath = roundToTwoDecimalPlaces(calculateIntegerMath()); @@ -82,7 +97,6 @@ public class IrisBenchmarking { BenchmarksCompleted++; calculateDataCompression = roundToTwoDecimalPlaces(calculateDataCompression()); }).thenRun(() -> { - BenchmarksCompleted++; elapsedTimeNs = stopBenchmarkTimer(); results(); inProgress = false; @@ -107,7 +121,7 @@ public class IrisBenchmarking { Iris.info("Benchmarks Completed: " + C.BLUE + BenchmarksCompleted + C.WHITE + " / " +"Total: " + C.BLUE + BenchmarksTotal); Iris.info("-----------------------------------------------------"); - previousCompleted = BenchmarksCompleted; // Update the previous value + previousCompleted = BenchmarksCompleted; } if (BenchmarksCompleted == BenchmarksTotal) { @@ -117,8 +131,6 @@ public class IrisBenchmarking { } } - - public static void results() { SystemInfo systemInfo = new SystemInfo(); @@ -129,7 +141,7 @@ public class IrisBenchmarking { long usedMemoryMB = totalMemoryMB - availableMemoryMB; MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); - Iris.info("OS: " + serverOS()); + Iris.info("OS: " + ServerOS); Iris.info("CPU Model: " + getCPUModel()); Iris.info("CPU Score: " + "WIP"); Iris.info("- Integer Math: " + calculateIntegerMath + " MOps/Sec"); @@ -138,13 +150,21 @@ public class IrisBenchmarking { Iris.info("- Random String Sorting: " + calculateStringSorting + " Thousand Strings/Sec"); Iris.info("- Data Encryption: " + formatDouble(calculateDataEncryption) + " MBytes/Sec"); Iris.info("- Data Compression: " + formatDouble(calculateDataCompression) + " MBytes/Sec"); - Iris.info("Disk Model: " + getDiskModel()); - Iris.info("- Average Write Speed: " + C.BLUE + formatDouble(avgWriteSpeedMBps) + " Mbp/Sec"); - Iris.info("- Average Read Speed: " + C.BLUE + formatDouble(avgReadSpeedMBps) + " Mbp/Sec"); - Iris.info("- Highest Write Speed: " + formatDouble(highestWriteSpeedMBps) + " Mbp/Sec"); - Iris.info("- Highest Read Speed: " + formatDouble(highestReadSpeedMBps) + " Mbp/Sec"); - Iris.info("- Lowest Write Speed: " + formatDouble(lowestWriteSpeedMBps) + " Mbp/Sec"); - Iris.info("- Lowest Read Speed: " + formatDouble(lowestReadSpeedMBps) + " Mbp/Sec"); + if(WindowsDiskSpeed) { + Iris.info("Disk Model: " + getDiskModel()); + Iris.info(C.BLUE + "- Running with Windows System Assessment Tool"); + Iris.info("- Sequential 64.0 Write: " + C.BLUE + formatDouble(avgWriteSpeedMBps) + " Mbps"); + Iris.info("- Sequential 64.0 Read: " + C.BLUE + formatDouble(avgReadSpeedMBps) + " Mbps"); + } else { + Iris.info("Disk Model: " + getDiskModel()); + Iris.info(C.YELLOW + "- Running in Native Mode"); + Iris.info("- Average Write Speed: " + C.BLUE + formatDouble(avgWriteSpeedMBps) + " Mbps"); + Iris.info("- Average Read Speed: " + C.BLUE + formatDouble(avgReadSpeedMBps) + " Mbps"); + Iris.info("- Highest Write Speed: " + formatDouble(highestWriteSpeedMBps) + " Mbps"); + Iris.info("- Highest Read Speed: " + formatDouble(highestReadSpeedMBps) + " Mbps"); + Iris.info("- Lowest Write Speed: " + formatDouble(lowestWriteSpeedMBps) + " Mbps"); + Iris.info("- Lowest Read Speed: " + formatDouble(lowestReadSpeedMBps) + " Mbps"); + } Iris.info("Ram Usage: "); Iris.info("- Total Ram: " + totalMemoryMB + " MB"); Iris.info("- Used Ram: " + usedMemoryMB + " MB"); @@ -161,11 +181,25 @@ public class IrisBenchmarking { long maxMemoryUsageMB = (maxHeapMemory + maxNonHeapMemory) / (1024 * 1024); return maxMemoryUsageMB; } - public static String serverOS() { + public static void getServerOS() { SystemInfo systemInfo = new SystemInfo(); OperatingSystem os = systemInfo.getOperatingSystem(); - String osInfo = os.toString(); - return osInfo; + ServerOS = os.toString(); + } + public static boolean isRunningAsAdmin() { + return ServerOS.contains("Windows") && isWindowsAdmin(); + } + private static boolean isUnixAdmin() { + return System.getProperty("user.name").equals("root"); + } + private static boolean isWindowsAdmin() { + String[] groups = (new com.sun.security.auth.module.NTSystem()).getGroupIDs(); + for (String group : groups) { + if (group.equals("S-1-5-32-544")) { + return true; + } + } + return false; } public static String getCPUModel() { try { @@ -188,6 +222,9 @@ public class IrisBenchmarking { return "Unknown Disk Model"; } } + public static void warningFallback(){ + Iris.info(C.RED + "Using the FALLBACK method for " + C.DARK_RED + currentRunning + C.RED +" due to compatibility issues. Please note that this may result in less accurate results."); + } private static String formatDouble(double value) { return String.format("%.2f", value); } @@ -200,40 +237,6 @@ public class IrisBenchmarking { long endTime = System.nanoTime(); return (endTime - startTime) / 1_000_000_000.0; } - public static double calculateCpuScore( - double calculateIntegerMath, - double calculateFloatingPoint, - double calculatePrimeNumbers, - double calculateStringSorting, - double calculateDataEncryption, - double calculateDataCompression - ) { - double weightIntegerMath = 1.0; - double weightFloatingPoint = 1.0; - double weightPrimeNumbers = 1.0; - double weightStringSorting = 1.0; - double weightDataEncryption = 1.0; - double weightDataCompression = 1.0; - - double invertedIntegerMath = 1.0 / calculateIntegerMath; - double invertedFloatingPoint = 1.0 / calculateFloatingPoint; - double invertedPrimeNumbers = 1.0 / calculatePrimeNumbers; - double invertedStringSorting = 1.0 / calculateStringSorting; - double invertedDataEncryption = 1.0 / calculateDataEncryption; - double invertedDataCompression = 1.0 / calculateDataCompression; - - double cpuScore = - ( - invertedIntegerMath * weightIntegerMath + - invertedFloatingPoint * weightFloatingPoint + - invertedPrimeNumbers * weightPrimeNumbers + - invertedStringSorting * weightStringSorting + - invertedDataEncryption * weightDataEncryption + - invertedDataCompression * weightDataCompression) / - (weightIntegerMath + weightFloatingPoint + weightPrimeNumbers + weightStringSorting + weightDataEncryption + weightDataCompression); - - return cpuScore; - } private static double calculateIntegerMath() { currentRunning = "calculateIntegerMath"; final int numIterations = 1_000_000_000; @@ -263,13 +266,11 @@ public class IrisBenchmarking { return averageMopsPerSec; } private static double calculateFloatingPoint() { + currentRunning = "calculateFloatingPoint"; long numIterations = 85_000_000; int numRuns = 30; - int percent = 10; double totalMopsPerSec = 0; - for (int run = 0; run < numRuns; run++) { - percent = percent + 5; double result = 0; long startTime = System.nanoTime(); @@ -509,4 +510,46 @@ public class IrisBenchmarking { } return sum / values.length; } + public static void WindowsDiskSpeedTest() { + + try { + String command = "winsat disk"; + Process process = Runtime.getRuntime().exec(command); + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + String line; + + while ((line = reader.readLine()) != null) { + Iris.debug(line); + + if (line.contains("Disk Sequential 64.0 Read")) { + avgReadSpeedMBps = extractSpeed(line); + } else if (line.contains("Disk Sequential 64.0 Write")) { + avgWriteSpeedMBps = extractSpeed(line); + } + } + + process.waitFor(); + process.destroy(); + + // Now you have the speeds in sequentialReadSpeed and sequentialWriteSpeed + Iris.debug("Sequential Read Speed: " + avgReadSpeedMBps + " MB/s"); + Iris.debug("Sequential Write Speed: " + avgWriteSpeedMBps + " MB/s"); + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + } + } + private static double extractSpeed(String line) { + String[] tokens = line.split("\\s+"); + for (int i = 0; i < tokens.length; i++) { + if (tokens[i].endsWith("MB/s") && i > 0) { + try { + return Double.parseDouble(tokens[i - 1]); + } catch (NumberFormatException e) { + e.printStackTrace(); + } + } + } + return 0.0; // Default value if parsing fails + } + } \ No newline at end of file From f129742a41d9d04550d97b073bfcb048b410bd5d Mon Sep 17 00:00:00 2001 From: RePixelatedMC Date: Sat, 21 Oct 2023 20:19:03 +0200 Subject: [PATCH 04/10] cleanup --- .../iris/core/tools/IrisBenchmarking.java | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java b/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java index 8151a1d29..eb3e3f95b 100644 --- a/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java +++ b/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java @@ -73,7 +73,7 @@ public class IrisBenchmarking { // help CompletableFuture future = CompletableFuture.runAsync(() -> { BenchmarksCompleted++; - if (ServerOS.contains("Windows") && isRunningAsAdmin()){ + if (ServerOS.contains("Windows") && isRunningAsAdmin()) { WindowsDiskSpeed = true; WindowsDiskSpeedTest(); } else { @@ -118,7 +118,7 @@ public class IrisBenchmarking { Iris.info("-----------------------------------------------------"); Iris.info("Currently Running: " + C.BLUE + currentRunning); // Iris.info("Tasks: " + "Current Tasks: " + C.BLUE + currentTasks + C.WHITE + " / " + "Total Tasks: " + C.BLUE + totalTasks); - Iris.info("Benchmarks Completed: " + C.BLUE + BenchmarksCompleted + C.WHITE + " / " +"Total: " + C.BLUE + BenchmarksTotal); + Iris.info("Benchmarks Completed: " + C.BLUE + BenchmarksCompleted + C.WHITE + " / " + "Total: " + C.BLUE + BenchmarksTotal); Iris.info("-----------------------------------------------------"); previousCompleted = BenchmarksCompleted; @@ -150,7 +150,7 @@ public class IrisBenchmarking { Iris.info("- Random String Sorting: " + calculateStringSorting + " Thousand Strings/Sec"); Iris.info("- Data Encryption: " + formatDouble(calculateDataEncryption) + " MBytes/Sec"); Iris.info("- Data Compression: " + formatDouble(calculateDataCompression) + " MBytes/Sec"); - if(WindowsDiskSpeed) { + if (WindowsDiskSpeed) { Iris.info("Disk Model: " + getDiskModel()); Iris.info(C.BLUE + "- Running with Windows System Assessment Tool"); Iris.info("- Sequential 64.0 Write: " + C.BLUE + formatDouble(avgWriteSpeedMBps) + " Mbps"); @@ -172,6 +172,7 @@ public class IrisBenchmarking { Iris.info("- Total Paging Size: " + totalPageSize + " MB"); Iris.info("Duration: " + roundToTwoDecimalPlaces(elapsedTimeNs) + " Seconds"); } + public static long getMaxMemoryUsage() { MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage(); @@ -181,17 +182,21 @@ public class IrisBenchmarking { long maxMemoryUsageMB = (maxHeapMemory + maxNonHeapMemory) / (1024 * 1024); return maxMemoryUsageMB; } + public static void getServerOS() { SystemInfo systemInfo = new SystemInfo(); OperatingSystem os = systemInfo.getOperatingSystem(); ServerOS = os.toString(); } + public static boolean isRunningAsAdmin() { return ServerOS.contains("Windows") && isWindowsAdmin(); } + private static boolean isUnixAdmin() { return System.getProperty("user.name").equals("root"); } + private static boolean isWindowsAdmin() { String[] groups = (new com.sun.security.auth.module.NTSystem()).getGroupIDs(); for (String group : groups) { @@ -201,6 +206,7 @@ public class IrisBenchmarking { } return false; } + public static String getCPUModel() { try { SystemInfo systemInfo = new SystemInfo(); @@ -212,6 +218,7 @@ public class IrisBenchmarking { return "Unknown CPU Model"; } } + public static String getDiskModel() { SystemInfo systemInfo = new SystemInfo(); List diskStores = systemInfo.getHardware().getDiskStores(); @@ -222,9 +229,11 @@ public class IrisBenchmarking { return "Unknown Disk Model"; } } - public static void warningFallback(){ - Iris.info(C.RED + "Using the FALLBACK method for " + C.DARK_RED + currentRunning + C.RED +" due to compatibility issues. Please note that this may result in less accurate results."); + + public static void warningFallback() { + Iris.info(C.RED + "Using the FALLBACK method for " + C.DARK_RED + currentRunning + C.RED + " due to compatibility issues. Please note that this may result in less accurate results."); } + private static String formatDouble(double value) { return String.format("%.2f", value); } @@ -237,6 +246,7 @@ public class IrisBenchmarking { long endTime = System.nanoTime(); return (endTime - startTime) / 1_000_000_000.0; } + private static double calculateIntegerMath() { currentRunning = "calculateIntegerMath"; final int numIterations = 1_000_000_000; @@ -265,6 +275,7 @@ public class IrisBenchmarking { double averageMopsPerSec = totalMopsPerSec / numRuns; return averageMopsPerSec; } + private static double calculateFloatingPoint() { currentRunning = "calculateFloatingPoint"; long numIterations = 85_000_000; @@ -288,6 +299,7 @@ public class IrisBenchmarking { double averageMopsPerSec = totalMopsPerSec / numRuns; return averageMopsPerSec; } + private static double calculatePrimeNumbers() { currentRunning = "calculatePrimeNumbers"; int primeCount; @@ -315,6 +327,7 @@ public class IrisBenchmarking { double averageMopsPerSec = totalMopsPerSec / numRuns; return averageMopsPerSec; } + private static double calculateStringSorting() { currentRunning = "calculateStringSorting"; int stringCount = 1_000_000; @@ -337,6 +350,7 @@ public class IrisBenchmarking { double averageMopsPerSec = totalMopsPerSec / numRuns; return averageMopsPerSec; } + public static double calculateDataEncryption() { currentRunning = "calculateDataEncryption"; int dataSizeMB = 100; @@ -358,6 +372,7 @@ public class IrisBenchmarking { double averageMBytesPerSec = totalMBytesPerSec / numRuns; return averageMBytesPerSec; } + private static byte[] performEncryption(byte[] data, int numRuns) { byte[] key = "MyEncryptionKey".getBytes(); byte[] result = Arrays.copyOf(data, data.length); @@ -368,6 +383,7 @@ public class IrisBenchmarking { } return result; } + public static double calculateDataCompression() { currentRunning = "calculateDataCompression"; int dataSizeMB = 500; @@ -381,6 +397,7 @@ public class IrisBenchmarking { return mbytesPerSec; } + private static byte[] performCompression(byte[] data) { Deflater deflater = new Deflater(); deflater.setInput(data); @@ -396,6 +413,7 @@ public class IrisBenchmarking { deflater.end(); return outputStream.toByteArray(); } + private static List generateRandomStrings(int count, int length) { SecureRandom random = new SecureRandom(); List randomStrings = new ArrayList<>(); @@ -407,18 +425,22 @@ public class IrisBenchmarking { }); return randomStrings; } + private static byte[] generateRandomData(int size) { SecureRandom random = new SecureRandom(); byte[] data = new byte[size]; random.nextBytes(data); return data; } + private static double roundToTwoDecimalPlaces(double value) { return Double.parseDouble(String.format("%.2f", value)); } + private static double calculateCPUScore(long elapsedTimeNs) { return 1.0 / (elapsedTimeNs / 1_000_000.0); } + public static double calculateDiskSpeed() { currentRunning = "calculateDiskSpeed"; String filePath = "benchmark.dat"; @@ -468,6 +490,7 @@ public class IrisBenchmarking { avgReadSpeedMBps = calculateAverage(readSpeeds); return 2; } + public static void createTestFile(String filePath, int fileSizeMB) { try { File file = new File(filePath); @@ -482,6 +505,7 @@ public class IrisBenchmarking { e.printStackTrace(); } } + public static void readTestFile(String filePath) { try { File file = new File(filePath); @@ -494,15 +518,18 @@ public class IrisBenchmarking { e.printStackTrace(); } } + public static void deleteTestFile(String filePath) { File file = new File(filePath); file.delete(); } + public static double calculateDiskSpeedMBps(int fileSizeMB, long startTime, long endTime) { double elapsedSeconds = (endTime - startTime) / 1_000_000_000.0; double writeSpeed = (fileSizeMB / elapsedSeconds); return writeSpeed; } + public static double calculateAverage(double[] values) { double sum = 0; for (double value : values) { @@ -510,6 +537,7 @@ public class IrisBenchmarking { } return sum / values.length; } + public static void WindowsDiskSpeedTest() { try { @@ -538,6 +566,7 @@ public class IrisBenchmarking { e.printStackTrace(); } } + private static double extractSpeed(String line) { String[] tokens = line.split("\\s+"); for (int i = 0; i < tokens.length; i++) { From 593e96a31a30bce60fd594a9005d4708703d6189 Mon Sep 17 00:00:00 2001 From: RePixelatedMC Date: Sun, 22 Oct 2023 08:47:33 +0200 Subject: [PATCH 05/10] added WindowsCPUSpeedTest --- .../iris/core/tools/IrisBenchmarking.java | 96 +++++++++++++++---- 1 file changed, 78 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java b/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java index eb3e3f95b..6e8dcd314 100644 --- a/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java +++ b/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java @@ -45,9 +45,13 @@ public class IrisBenchmarking { static double calculateDataCompression; static String currentRunning = "None"; static int BenchmarksCompleted = -1; - static int BenchmarksTotal = 6; + static int BenchmarksTotal = 7; static int totalTasks = 10; static int currentTasks = 0; + static double WindowsCPUCompression; + static double WindowsCPUEncryption; + static double WindowsCPUVistaCompression; + static double WindowsCPUCSHA1; static double elapsedTimeNs; static boolean WindowsDiskSpeed = false; public static boolean inProgress = false; @@ -81,6 +85,20 @@ public class IrisBenchmarking { doneCalculateDiskSpeed.set(roundToTwoDecimalPlaces(calculateDiskSpeed())); } + }).thenRun(() -> { + BenchmarksCompleted++; + if (ServerOS.contains("Windows") && isRunningAsAdmin()) { + WindowsCpuSpeedTest(); + } else { + Iris.info("Skipping:" + C.BLUE + " Windows System Assessment Tool Benchmarks"); + if (ServerOS.contains("Windows")) { + Iris.info("Required Software:" + C.BLUE +" Windows"); + } + if (isRunningAsAdmin()){ + Iris.info( C.RED + "Elevated privileges missing"); + } + } + }).thenRun(() -> { BenchmarksCompleted++; calculateIntegerMath = roundToTwoDecimalPlaces(calculateIntegerMath()); @@ -90,6 +108,9 @@ public class IrisBenchmarking { }).thenRun(() -> { BenchmarksCompleted++; calculateStringSorting = roundToTwoDecimalPlaces(calculateStringSorting()); + }).thenRun(() -> { + BenchmarksCompleted++; + calculatePrimeNumbers = roundToTwoDecimalPlaces(calculatePrimeNumbers()); }).thenRun(() -> { BenchmarksCompleted++; calculateDataEncryption = roundToTwoDecimalPlaces(calculateDataEncryption()); @@ -142,6 +163,7 @@ public class IrisBenchmarking { MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); Iris.info("OS: " + ServerOS); + if(!isRunningAsAdmin() || !ServerOS.contains("Windows")){ Iris.info(C.GOLD + "For the full results use Windows + Admin Rights..");} Iris.info("CPU Model: " + getCPUModel()); Iris.info("CPU Score: " + "WIP"); Iris.info("- Integer Math: " + calculateIntegerMath + " MOps/Sec"); @@ -150,6 +172,7 @@ public class IrisBenchmarking { Iris.info("- Random String Sorting: " + calculateStringSorting + " Thousand Strings/Sec"); Iris.info("- Data Encryption: " + formatDouble(calculateDataEncryption) + " MBytes/Sec"); Iris.info("- Data Compression: " + formatDouble(calculateDataCompression) + " MBytes/Sec"); + if (WindowsDiskSpeed) { Iris.info("Disk Model: " + getDiskModel()); Iris.info(C.BLUE + "- Running with Windows System Assessment Tool"); @@ -157,9 +180,9 @@ public class IrisBenchmarking { Iris.info("- Sequential 64.0 Read: " + C.BLUE + formatDouble(avgReadSpeedMBps) + " Mbps"); } else { Iris.info("Disk Model: " + getDiskModel()); - Iris.info(C.YELLOW + "- Running in Native Mode"); - Iris.info("- Average Write Speed: " + C.BLUE + formatDouble(avgWriteSpeedMBps) + " Mbps"); - Iris.info("- Average Read Speed: " + C.BLUE + formatDouble(avgReadSpeedMBps) + " Mbps"); + Iris.info(C.GREEN + "- Running in Native Mode"); + Iris.info("- Average Write Speed: " + C.GREEN + formatDouble(avgWriteSpeedMBps) + " Mbps"); + Iris.info("- Average Read Speed: " + C.GREEN + formatDouble(avgReadSpeedMBps) + " Mbps"); Iris.info("- Highest Write Speed: " + formatDouble(highestWriteSpeedMBps) + " Mbps"); Iris.info("- Highest Read Speed: " + formatDouble(highestReadSpeedMBps) + " Mbps"); Iris.info("- Lowest Write Speed: " + formatDouble(lowestWriteSpeedMBps) + " Mbps"); @@ -170,7 +193,12 @@ public class IrisBenchmarking { Iris.info("- Used Ram: " + usedMemoryMB + " MB"); Iris.info("- Total Process Ram: " + C.BLUE + getMaxMemoryUsage() + " MB"); Iris.info("- Total Paging Size: " + totalPageSize + " MB"); + Iris.info(C.BLUE + "Windows System Assessment Tool: "); + Iris.info("- CPU LZW Compression:" + C.BLUE + formatDouble(WindowsCPUCompression) + " MB/s"); + Iris.info("- CPU AES256 Encryption: " + C.BLUE + formatDouble(WindowsCPUEncryption) + " MB/s"); + Iris.info("- CPU SHA1 Hash: " + C.BLUE + formatDouble(WindowsCPUCSHA1) + " MB/s"); Iris.info("Duration: " + roundToTwoDecimalPlaces(elapsedTimeNs) + " Seconds"); + } public static long getMaxMemoryUsage() { @@ -190,21 +218,10 @@ public class IrisBenchmarking { } public static boolean isRunningAsAdmin() { - return ServerOS.contains("Windows") && isWindowsAdmin(); - } + if (ServerOS.contains("Windows")){ - private static boolean isUnixAdmin() { - return System.getProperty("user.name").equals("root"); - } - - private static boolean isWindowsAdmin() { - String[] groups = (new com.sun.security.auth.module.NTSystem()).getGroupIDs(); - for (String group : groups) { - if (group.equals("S-1-5-32-544")) { - return true; - } } - return false; + return true; } public static String getCPUModel() { @@ -539,7 +556,7 @@ public class IrisBenchmarking { } public static void WindowsDiskSpeedTest() { - + currentRunning = "calculateDiskSpeed"; try { String command = "winsat disk"; Process process = Runtime.getRuntime().exec(command); @@ -580,5 +597,48 @@ public class IrisBenchmarking { } return 0.0; // Default value if parsing fails } + public static void WindowsCpuSpeedTest() { + currentRunning = "calculateCpuTest"; + try { + String command = "winsat cpuformal"; + Process process = Runtime.getRuntime().exec(command); + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + String line; + + while ((line = reader.readLine()) != null) { + Iris.debug(line); + + if (line.contains("CPU AES256 Encryption")) { + WindowsCPUEncryption = extractCpuInfo(line); + } + if (line.contains("CPU LZW Compression")) { + WindowsCPUCompression = extractCpuInfo(line); + } + if (line.contains("CPU SHA1 Hash")) { + WindowsCPUCSHA1 = extractCpuInfo(line); + } + } + process.waitFor(); + process.destroy(); + + Iris.debug("Winsat Encryption: " + WindowsCPUEncryption + " MB/s"); + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + } + } + + private static double extractCpuInfo(String line) { + String[] tokens = line.split("\\s+"); + for (int i = 0; i < tokens.length; i++) { + if (tokens[i].endsWith("MB/s") && i > 0) { + try { + return Double.parseDouble(tokens[i - 1]); + } catch (NumberFormatException e) { + e.printStackTrace(); + } + } + } + return 0.0; + } } \ No newline at end of file From 3bca1f5304604fe637b383301f7b0a5a87240a26 Mon Sep 17 00:00:00 2001 From: RePixelatedMC Date: Sun, 22 Oct 2023 09:20:13 +0200 Subject: [PATCH 06/10] Fixes? --- .../iris/core/tools/IrisBenchmarking.java | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java b/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java index 6e8dcd314..82b840b8b 100644 --- a/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java +++ b/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java @@ -50,9 +50,9 @@ public class IrisBenchmarking { static int currentTasks = 0; static double WindowsCPUCompression; static double WindowsCPUEncryption; - static double WindowsCPUVistaCompression; static double WindowsCPUCSHA1; static double elapsedTimeNs; + static boolean Winsat = false; static boolean WindowsDiskSpeed = false; public static boolean inProgress = false; // Good enough for now. . . @@ -88,14 +88,17 @@ public class IrisBenchmarking { }).thenRun(() -> { BenchmarksCompleted++; if (ServerOS.contains("Windows") && isRunningAsAdmin()) { + Winsat = true; WindowsCpuSpeedTest(); } else { Iris.info("Skipping:" + C.BLUE + " Windows System Assessment Tool Benchmarks"); - if (ServerOS.contains("Windows")) { + if (!ServerOS.contains("Windows")) { Iris.info("Required Software:" + C.BLUE +" Windows"); + BenchmarksTotal = 6; } - if (isRunningAsAdmin()){ - Iris.info( C.RED + "Elevated privileges missing"); + if (!isRunningAsAdmin()){ + Iris.info( C.RED + "ERROR: " + C.DARK_RED +"Elevated privileges missing"); + BenchmarksTotal = 6; } } @@ -193,11 +196,13 @@ public class IrisBenchmarking { Iris.info("- Used Ram: " + usedMemoryMB + " MB"); Iris.info("- Total Process Ram: " + C.BLUE + getMaxMemoryUsage() + " MB"); Iris.info("- Total Paging Size: " + totalPageSize + " MB"); - Iris.info(C.BLUE + "Windows System Assessment Tool: "); - Iris.info("- CPU LZW Compression:" + C.BLUE + formatDouble(WindowsCPUCompression) + " MB/s"); - Iris.info("- CPU AES256 Encryption: " + C.BLUE + formatDouble(WindowsCPUEncryption) + " MB/s"); - Iris.info("- CPU SHA1 Hash: " + C.BLUE + formatDouble(WindowsCPUCSHA1) + " MB/s"); - Iris.info("Duration: " + roundToTwoDecimalPlaces(elapsedTimeNs) + " Seconds"); + if (Winsat) { + Iris.info(C.BLUE + "Windows System Assessment Tool: "); + Iris.info("- CPU LZW Compression:" + C.BLUE + formatDouble(WindowsCPUCompression) + " MB/s"); + Iris.info("- CPU AES256 Encryption: " + C.BLUE + formatDouble(WindowsCPUEncryption) + " MB/s"); + Iris.info("- CPU SHA1 Hash: " + C.BLUE + formatDouble(WindowsCPUCSHA1) + " MB/s"); + Iris.info("Duration: " + roundToTwoDecimalPlaces(elapsedTimeNs) + " Seconds"); + } } @@ -218,10 +223,16 @@ public class IrisBenchmarking { } public static boolean isRunningAsAdmin() { - if (ServerOS.contains("Windows")){ - + if (ServerOS.contains("Windows")) { + try { + Process process = Runtime.getRuntime().exec("winsat disk"); + process.waitFor(); + return process.exitValue() == 0; + } catch (IOException | InterruptedException e) { + // Handle exceptions as needed + } } - return true; + return false; // Default to false if checks fail } public static String getCPUModel() { @@ -248,7 +259,8 @@ public class IrisBenchmarking { } public static void warningFallback() { - Iris.info(C.RED + "Using the FALLBACK method for " + C.DARK_RED + currentRunning + C.RED + " due to compatibility issues. Please note that this may result in less accurate results."); + Iris.info(C.RED + "Using the FALLBACK method due to compatibility issues. "); + Iris.info(C.RED + "Please note that this may result in less accurate results."); } private static String formatDouble(double value) { From 81e3fd346a85b3ff9c2161a0d97449d7d54482e0 Mon Sep 17 00:00:00 2001 From: RePixelatedMC Date: Sun, 22 Oct 2023 10:13:18 +0200 Subject: [PATCH 07/10] Rewrote The update process and made it more manual --- .../iris/core/tools/IrisBenchmarking.java | 71 +++++++++++-------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java b/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java index 82b840b8b..2f0aaea7e 100644 --- a/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java +++ b/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java @@ -44,7 +44,7 @@ public class IrisBenchmarking { static double calculateDataEncryption; static double calculateDataCompression; static String currentRunning = "None"; - static int BenchmarksCompleted = -1; + static int BenchmarksCompleted = 0; static int BenchmarksTotal = 7; static int totalTasks = 10; static int currentTasks = 0; @@ -65,28 +65,29 @@ public class IrisBenchmarking { startBenchmarkTimer(); Iris.info("Benchmark Started!"); Iris.warn("Although it may seem momentarily paused, it's actively processing."); - Thread progressBarThread = new Thread(() -> { - try { - progressBar(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - }); - progressBarThread.start(); // help CompletableFuture future = CompletableFuture.runAsync(() -> { - BenchmarksCompleted++; + currentRunning = "calculateDiskSpeed"; + progressBar(); if (ServerOS.contains("Windows") && isRunningAsAdmin()) { WindowsDiskSpeed = true; WindowsDiskSpeedTest(); } else { warningFallback(); + try { + Thread.sleep(10); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } doneCalculateDiskSpeed.set(roundToTwoDecimalPlaces(calculateDiskSpeed())); + BenchmarksCompleted++; } + }).thenRun(() -> { - BenchmarksCompleted++; + currentRunning = "WindowsCpuSpeedTest"; + progressBar(); if (ServerOS.contains("Windows") && isRunningAsAdmin()) { Winsat = true; WindowsCpuSpeedTest(); @@ -103,23 +104,35 @@ public class IrisBenchmarking { } }).thenRun(() -> { - BenchmarksCompleted++; + currentRunning = "calculateIntegerMath"; + progressBar(); calculateIntegerMath = roundToTwoDecimalPlaces(calculateIntegerMath()); - }).thenRun(() -> { BenchmarksCompleted++; + }).thenRun(() -> { + currentRunning = "calculateFloatingPoint"; + progressBar(); calculateFloatingPoint = roundToTwoDecimalPlaces(calculateFloatingPoint()); - }).thenRun(() -> { BenchmarksCompleted++; + }).thenRun(() -> { + currentRunning = "calculateStringSorting"; + progressBar(); calculateStringSorting = roundToTwoDecimalPlaces(calculateStringSorting()); - }).thenRun(() -> { BenchmarksCompleted++; + }).thenRun(() -> { + currentRunning = "calculatePrimeNumbers"; + progressBar(); calculatePrimeNumbers = roundToTwoDecimalPlaces(calculatePrimeNumbers()); - }).thenRun(() -> { BenchmarksCompleted++; + }).thenRun(() -> { + currentRunning = "calculateDataEncryption"; + progressBar(); calculateDataEncryption = roundToTwoDecimalPlaces(calculateDataEncryption()); - }).thenRun(() -> { BenchmarksCompleted++; + }).thenRun(() -> { + currentRunning = "calculateDataCompression"; + progressBar(); calculateDataCompression = roundToTwoDecimalPlaces(calculateDataCompression()); + BenchmarksCompleted++; }).thenRun(() -> { elapsedTimeNs = stopBenchmarkTimer(); results(); @@ -133,8 +146,16 @@ public class IrisBenchmarking { } } - private static int previousCompleted = BenchmarksCompleted; + public static void progressBar(){ + Iris.info("-----------------------------------------------------"); + Iris.info("Currently Running: " + C.BLUE + currentRunning); + // Iris.info("Tasks: " + "Current Tasks: " + C.BLUE + currentTasks + C.WHITE + " / " + "Total Tasks: " + C.BLUE + totalTasks); + Iris.info("Benchmarks Completed: " + C.BLUE + BenchmarksCompleted + C.WHITE + " / " + "Total: " + C.BLUE + BenchmarksTotal); + Iris.info("-----------------------------------------------------"); + } + /* + private static int previousCompleted = BenchmarksCompleted; // why just why public static void progressBar() throws InterruptedException { while (true) { @@ -154,6 +175,7 @@ public class IrisBenchmarking { Thread.sleep(10); } } + */ public static void results() { @@ -259,7 +281,7 @@ public class IrisBenchmarking { } public static void warningFallback() { - Iris.info(C.RED + "Using the FALLBACK method due to compatibility issues. "); + Iris.info(C.RED + "Using the " + C.DARK_RED + "FALLBACK" +C.RED +" method due to compatibility issues. "); Iris.info(C.RED + "Please note that this may result in less accurate results."); } @@ -277,7 +299,6 @@ public class IrisBenchmarking { } private static double calculateIntegerMath() { - currentRunning = "calculateIntegerMath"; final int numIterations = 1_000_000_000; final int numRuns = 30; double totalMopsPerSec = 0; @@ -306,7 +327,6 @@ public class IrisBenchmarking { } private static double calculateFloatingPoint() { - currentRunning = "calculateFloatingPoint"; long numIterations = 85_000_000; int numRuns = 30; double totalMopsPerSec = 0; @@ -330,7 +350,6 @@ public class IrisBenchmarking { } private static double calculatePrimeNumbers() { - currentRunning = "calculatePrimeNumbers"; int primeCount; long numIterations = 1_000_000; int numRuns = 30; @@ -358,7 +377,6 @@ public class IrisBenchmarking { } private static double calculateStringSorting() { - currentRunning = "calculateStringSorting"; int stringCount = 1_000_000; int stringLength = 100; int numRuns = 30; @@ -381,7 +399,6 @@ public class IrisBenchmarking { } public static double calculateDataEncryption() { - currentRunning = "calculateDataEncryption"; int dataSizeMB = 100; byte[] dataToEncrypt = generateRandomData(dataSizeMB * 1024 * 1024); int numRuns = 20; @@ -414,7 +431,6 @@ public class IrisBenchmarking { } public static double calculateDataCompression() { - currentRunning = "calculateDataCompression"; int dataSizeMB = 500; byte[] dataToCompress = generateRandomData(dataSizeMB * 1024 * 1024); long startTime = System.nanoTime(); @@ -471,7 +487,6 @@ public class IrisBenchmarking { } public static double calculateDiskSpeed() { - currentRunning = "calculateDiskSpeed"; String filePath = "benchmark.dat"; int numRuns = 10; int fileSizeMB = 1000; @@ -568,7 +583,6 @@ public class IrisBenchmarking { } public static void WindowsDiskSpeedTest() { - currentRunning = "calculateDiskSpeed"; try { String command = "winsat disk"; Process process = Runtime.getRuntime().exec(command); @@ -610,7 +624,6 @@ public class IrisBenchmarking { return 0.0; // Default value if parsing fails } public static void WindowsCpuSpeedTest() { - currentRunning = "calculateCpuTest"; try { String command = "winsat cpuformal"; Process process = Runtime.getRuntime().exec(command); @@ -653,4 +666,6 @@ public class IrisBenchmarking { return 0.0; } + // JMH BENCHMARKS oh boi here we go again + } \ No newline at end of file From f5c499ab6084878c96c80bb3010cce129d05741c Mon Sep 17 00:00:00 2001 From: RePixelatedMC Date: Sun, 22 Oct 2023 10:40:40 +0200 Subject: [PATCH 08/10] Fixes + cleanup --- .../volmit/iris/core/tools/IrisBenchmarking.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java b/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java index 2f0aaea7e..36bcd24fc 100644 --- a/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java +++ b/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java @@ -94,11 +94,11 @@ public class IrisBenchmarking { } else { Iris.info("Skipping:" + C.BLUE + " Windows System Assessment Tool Benchmarks"); if (!ServerOS.contains("Windows")) { - Iris.info("Required Software:" + C.BLUE +" Windows"); + Iris.info("Required Software:" + C.BLUE + " Windows"); BenchmarksTotal = 6; } - if (!isRunningAsAdmin()){ - Iris.info( C.RED + "ERROR: " + C.DARK_RED +"Elevated privileges missing"); + if (!isRunningAsAdmin()) { + Iris.info(C.RED + "ERROR: " + C.DARK_RED + "Elevated privileges missing"); BenchmarksTotal = 6; } } @@ -146,7 +146,7 @@ public class IrisBenchmarking { } } - public static void progressBar(){ + public static void progressBar() { Iris.info("-----------------------------------------------------"); Iris.info("Currently Running: " + C.BLUE + currentRunning); // Iris.info("Tasks: " + "Current Tasks: " + C.BLUE + currentTasks + C.WHITE + " / " + "Total Tasks: " + C.BLUE + totalTasks); @@ -188,7 +188,9 @@ public class IrisBenchmarking { MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); Iris.info("OS: " + ServerOS); - if(!isRunningAsAdmin() || !ServerOS.contains("Windows")){ Iris.info(C.GOLD + "For the full results use Windows + Admin Rights..");} + if (!isRunningAsAdmin() || !ServerOS.contains("Windows")) { + Iris.info(C.GOLD + "For the full results use Windows + Admin Rights.."); + } Iris.info("CPU Model: " + getCPUModel()); Iris.info("CPU Score: " + "WIP"); Iris.info("- Integer Math: " + calculateIntegerMath + " MOps/Sec"); @@ -281,7 +283,7 @@ public class IrisBenchmarking { } public static void warningFallback() { - Iris.info(C.RED + "Using the " + C.DARK_RED + "FALLBACK" +C.RED +" method due to compatibility issues. "); + Iris.info(C.RED + "Using the " + C.DARK_RED + "FALLBACK" + C.RED + " method due to compatibility issues. "); Iris.info(C.RED + "Please note that this may result in less accurate results."); } @@ -623,6 +625,7 @@ public class IrisBenchmarking { } return 0.0; // Default value if parsing fails } + public static void WindowsCpuSpeedTest() { try { String command = "winsat cpuformal"; From 1b0ff36d51531d659ae6b97d7f1f04a5cef9c594 Mon Sep 17 00:00:00 2001 From: RePixelatedMC Date: Sun, 22 Oct 2023 10:44:32 +0200 Subject: [PATCH 09/10] cleanup --- .../iris/core/tools/IrisBenchmarking.java | 36 ++++--------------- 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java b/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java index 36bcd24fc..2eb38e50c 100644 --- a/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java +++ b/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java @@ -30,6 +30,7 @@ import static com.google.common.math.LongMath.isPrime; public class IrisBenchmarking { static String ServerOS; + static String filePath = "benchmark.dat"; private static long startTime; static double avgWriteSpeedMBps; static double avgReadSpeedMBps; @@ -60,7 +61,7 @@ public class IrisBenchmarking { public static void runBenchmark() throws InterruptedException { inProgress = true; getServerOS(); - + deleteTestFile(filePath); AtomicReference doneCalculateDiskSpeed = new AtomicReference<>((double) 0); startBenchmarkTimer(); Iris.info("Benchmark Started!"); @@ -154,29 +155,6 @@ public class IrisBenchmarking { Iris.info("-----------------------------------------------------"); } - /* - private static int previousCompleted = BenchmarksCompleted; - // why just why - public static void progressBar() throws InterruptedException { - while (true) { - if (BenchmarksCompleted > previousCompleted) { - Iris.info("-----------------------------------------------------"); - Iris.info("Currently Running: " + C.BLUE + currentRunning); - // Iris.info("Tasks: " + "Current Tasks: " + C.BLUE + currentTasks + C.WHITE + " / " + "Total Tasks: " + C.BLUE + totalTasks); - Iris.info("Benchmarks Completed: " + C.BLUE + BenchmarksCompleted + C.WHITE + " / " + "Total: " + C.BLUE + BenchmarksTotal); - Iris.info("-----------------------------------------------------"); - - previousCompleted = BenchmarksCompleted; - } - - if (BenchmarksCompleted == BenchmarksTotal) { - break; - } - Thread.sleep(10); - } - } - */ - public static void results() { SystemInfo systemInfo = new SystemInfo(); @@ -253,10 +231,10 @@ public class IrisBenchmarking { process.waitFor(); return process.exitValue() == 0; } catch (IOException | InterruptedException e) { - // Handle exceptions as needed + // Hmm } } - return false; // Default to false if checks fail + return false; } public static String getCPUModel() { @@ -489,7 +467,6 @@ public class IrisBenchmarking { } public static double calculateDiskSpeed() { - String filePath = "benchmark.dat"; int numRuns = 10; int fileSizeMB = 1000; @@ -604,7 +581,6 @@ public class IrisBenchmarking { process.waitFor(); process.destroy(); - // Now you have the speeds in sequentialReadSpeed and sequentialWriteSpeed Iris.debug("Sequential Read Speed: " + avgReadSpeedMBps + " MB/s"); Iris.debug("Sequential Write Speed: " + avgWriteSpeedMBps + " MB/s"); } catch (IOException | InterruptedException e) { @@ -623,7 +599,7 @@ public class IrisBenchmarking { } } } - return 0.0; // Default value if parsing fails + return 0.0; } public static void WindowsCpuSpeedTest() { @@ -669,6 +645,6 @@ public class IrisBenchmarking { return 0.0; } - // JMH BENCHMARKS oh boi here we go again + // todo JMH BENCHMARKS } \ No newline at end of file From 0175cfa9864a02804a1cd837d00f28cdc04ee7fe Mon Sep 17 00:00:00 2001 From: RePixelatedMC Date: Sun, 22 Oct 2023 10:54:12 +0200 Subject: [PATCH 10/10] fixes --- src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java b/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java index 2eb38e50c..809a3f964 100644 --- a/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java +++ b/src/main/java/com/volmit/iris/core/tools/IrisBenchmarking.java @@ -66,6 +66,7 @@ public class IrisBenchmarking { startBenchmarkTimer(); Iris.info("Benchmark Started!"); Iris.warn("Although it may seem momentarily paused, it's actively processing."); + BenchmarksCompleted = 0; // help CompletableFuture future = CompletableFuture.runAsync(() -> {