Skip to content

Instantly share code, notes, and snippets.

@paplorinc
Created February 22, 2023 09:01
Show Gist options
  • Save paplorinc/d9ea3e6b10015c8207fa3f4e6f867be6 to your computer and use it in GitHub Desktop.
Save paplorinc/d9ea3e6b10015c8207fa3f4e6f867be6 to your computer and use it in GitHub Desktop.
@BenchmarkMode(Mode.Throughput)
@State(Scope.Benchmark)
@Fork(value = 1)
@Measurement(iterations = 3, time = 1)
@Warmup(iterations = 3, time = 1)
public class LongNumberParsing {
static final String DIGITS = "1234567890";
static final int REPETITIONS = 100;
static final String LONG_INT = join("", nCopies(REPETITIONS, DIGITS));
static final String LONG_FP = DIGITS + "." + join("", nCopies(REPETITIONS - 1, DIGITS));
@Benchmark public double perfParseDouble() { return Double.parseDouble(LONG_FP); }
@Benchmark public Object perfParseBigDecimal() { return new BigDecimal(LONG_FP); }
@Benchmark public Object perfParseBigInteger() { return new BigInteger(LONG_INT); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment