use of com.electronwill.nightconfig.core.io.WritingMode in project MinecraftForge by MinecraftForge.
the class ForgeConfigSpecTest method executeSpeedTest.
private <T> void executeSpeedTest(final String configKey, final T defaultKeyValue, final String testName) throws IOException {
final ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
final ForgeConfigSpec.ConfigValue<T> simpleValue = builder.define(configKey, defaultKeyValue);
final ForgeConfigSpec spec = builder.build();
final String configPath = String.format(Locale.ROOT, TEST_CONFIG_PATH_TEMPLATE, testName);
final File configFile = new File(configPath);
configFile.getParentFile().mkdirs();
configFile.createNewFile();
final CommentedFileConfig configData = CommentedFileConfig.builder(configPath).sync().preserveInsertionOrder().onFileNotFound((newfile, configFormat) -> {
Files.createFile(newfile);
return true;
}).writingMode(WritingMode.REPLACE).build();
spec.setConfig(configData);
final List<TestResult> results = runTestHarness(defaultKeyValue, testName, simpleValue, spec, 3, 20);
final double averageEnabled = results.stream().mapToLong(value -> value.enabledWatch.elapsed(TimeUnit.NANOSECONDS)).average().getAsDouble();
final double averageDisabled = results.stream().mapToLong(value -> value.disabledWatch.elapsed(TimeUnit.NANOSECONDS)).average().getAsDouble();
final double maxEnabledDeviation = results.stream().mapToLong(value -> value.enabledWatch.elapsed(TimeUnit.NANOSECONDS)).mapToDouble(e -> e - averageEnabled).map(Math::abs).max().getAsDouble();
final double maxDisabledDeviation = results.stream().mapToLong(value -> value.disabledWatch.elapsed(TimeUnit.NANOSECONDS)).mapToDouble(e -> e - averageDisabled).map(Math::abs).max().getAsDouble();
System.out.printf("Computed test results for: %s:%n", testName);
System.out.printf(" > Enabled: ~%10.2f ns. +- %10.2f ns.%n", averageEnabled, maxEnabledDeviation);
System.out.printf(" > Disabled: ~%10.2f ns. +- %10.2f ns.%n", averageDisabled, maxDisabledDeviation);
configFile.delete();
}
Aggregations