forked from dropwizard/dropwizard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add data size class adhering to the correct SI and IEC prefixes (drop…
…wizard#2686) The `Size` and `SizeUnit` classes in Dropwizard are using a common but incorrect definition of data size units, in which 1 kilobyte equals 1024 bytes. The `DataSize` and `DataSizeUnit` classes are using the correct definitions according to SI and IEC, in which 1 kilobyte equals 1000 bytes and 1 kibibytes equals 1024 bytes. Instead of modifying the existing `Size` and `SizeUnit` classes, this change set introduces a new set of classes, `DataSize` and `DataSizeUnit`, with the possibility to convert the old units into the new, correct units. Example: ``` assertEquals(Size.parse("128 kb").toDataSize(), DataSize.kibibytes(128L)); ``` This is a breaking change and has to be properly documented in the release notes and upgrade notes of Dropwizard. Closes dropwizard#2152 Closes dropwizard#2154
- Loading branch information
Showing
37 changed files
with
2,070 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
dropwizard-benchmarks/src/main/java/io/dropwizard/benchmarks/util/DataSizeBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.dropwizard.benchmarks.util; | ||
|
||
import io.dropwizard.util.DataSize; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@BenchmarkMode(Mode.AverageTime) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@State(Scope.Benchmark) | ||
public class DataSizeBenchmark { | ||
|
||
/** | ||
* Don't trust the IDE, it's advisedly non-final to avoid constant folding | ||
*/ | ||
private String size = "256KiB"; | ||
|
||
@Benchmark | ||
public DataSize parseSize() { | ||
return DataSize.parse(size); | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
new Runner(new OptionsBuilder() | ||
.include(DataSizeBenchmark.class.getSimpleName()) | ||
.forks(1) | ||
.warmupIterations(5) | ||
.measurementIterations(5) | ||
.build()) | ||
.run(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.