aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorgjoranv <gv@oath.com>2018-09-18 11:47:46 +0200
committergjoranv <gv@oath.com>2019-01-21 15:09:21 +0100
commitcd5957a7fae00e4bd598960aec83cb24896ef62a (patch)
treefb19c7bb95f0405472bcf03172a681e20758590a /vespajlib
parent3062c19ee29a6d02d5602349e82b540dbe395cda (diff)
Remove deprecated DoubleFormatter with tests.
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/src/main/java/com/yahoo/text/DoubleFormatter.java35
-rw-r--r--vespajlib/src/test/java/com/yahoo/text/DoubleFormatterTestCase.java205
-rw-r--r--vespajlib/src/test/java/com/yahoo/text/DoubleToStringBenchmark.java124
3 files changed, 0 insertions, 364 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/text/DoubleFormatter.java b/vespajlib/src/main/java/com/yahoo/text/DoubleFormatter.java
deleted file mode 100644
index 7281f3cd9d6..00000000000
--- a/vespajlib/src/main/java/com/yahoo/text/DoubleFormatter.java
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.text;
-
-/**
- * Utility class to format a double into a String.
- * <p>
- * This was intended as a lower-cost replacement for the standard
- * String.valueOf(double) since that method used to cause contention.
- * <p>
- * The contention issue is fixed in Java 8u96 so this class is now obsolete.
- *
- * @author arnej27959
- */
-
-@Deprecated
-public final class DoubleFormatter {
-
- public static StringBuilder fmt(StringBuilder target, double v) {
- target.append(v);
- return target;
- }
-
- public static String stringValue(double v) {
- return String.valueOf(v);
- }
-
- public static void append(StringBuilder s, double d) {
- s.append(d);
- }
-
- public static void append(StringBuilder s, int i) {
- s.append(i);
- }
-
-}
diff --git a/vespajlib/src/test/java/com/yahoo/text/DoubleFormatterTestCase.java b/vespajlib/src/test/java/com/yahoo/text/DoubleFormatterTestCase.java
deleted file mode 100644
index 3d0c623bbf4..00000000000
--- a/vespajlib/src/test/java/com/yahoo/text/DoubleFormatterTestCase.java
+++ /dev/null
@@ -1,205 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.text;
-
-import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-
-@SuppressWarnings("deprecation")
-/**
- * @author arnej27959
- */
-public class DoubleFormatterTestCase {
-
- @Test
- public void testZero() {
- String zero = DoubleFormatter.stringValue(0.0);
- //assertEquals("0.0", zero);
- }
-
- @Test
- public void testOne() {
- String one = DoubleFormatter.stringValue(1.0);
- assertEquals("1.0", one);
- }
-
- @Test
- public void testMinusOne() {
- String one = DoubleFormatter.stringValue(-1.0);
- assertEquals("-1.0", one);
- }
-
- @Test
- public void testNanInf() {
- String plusInf = DoubleFormatter.stringValue(Double.POSITIVE_INFINITY);
- assertEquals("Infinity", plusInf);
-
- String notAnum = DoubleFormatter.stringValue(Double.NaN);
- assertEquals("NaN", notAnum);
-
- String negInf = DoubleFormatter.stringValue(Double.NEGATIVE_INFINITY);
- assertEquals("-Infinity", negInf);
- }
-
- @Test
- public void testSeven() {
- String seven = DoubleFormatter.stringValue(7.0);
- assertEquals("7.0", seven);
-
- seven = DoubleFormatter.stringValue(77.0);
- assertEquals("77.0", seven);
-
- seven = DoubleFormatter.stringValue(7777.0);
- assertEquals("7777.0", seven);
-
- seven = DoubleFormatter.stringValue(7777007777.0);
- assertEquals("7.777007777E9", seven);
- }
-
-
- @Test
- public void testSomeChosenNumbers() {
- String s = DoubleFormatter.stringValue(4097.0);
- assertEquals("4097.0", s);
-
- s = DoubleFormatter.stringValue(4097.5);
- assertEquals("4097.5", s);
-
- s = DoubleFormatter.stringValue(1073741823.0);
- assertEquals("1.073741823E9", s);
-
- s = DoubleFormatter.stringValue(1073741823.5);
- assertEquals("1.0737418235E9", s);
-
- s = DoubleFormatter.stringValue(1073741825.5);
- assertEquals("1.0737418255E9", s);
-
- s = DoubleFormatter.stringValue(1.23456789012345669);
- assertEquals("1.2345678901234567", s);
- s = DoubleFormatter.stringValue(12.3456789012345673);
- assertEquals("12.345678901234567", s);
- s = DoubleFormatter.stringValue(123.456789012345666);
- assertEquals("123.45678901234567", s);
- s = DoubleFormatter.stringValue(1234.56789012345666);
- assertEquals("1234.5678901234567", s);
- s = DoubleFormatter.stringValue(12345.6789012345670);
- assertEquals("12345.678901234567", s);
- s = DoubleFormatter.stringValue(123456.789012345674);
- assertEquals("123456.78901234567", s);
- s = DoubleFormatter.stringValue(1234567.89012345671);
- assertEquals("1234567.8901234567", s);
-
- s = DoubleFormatter.stringValue(0.99);
- // assertEquals("0.99", s);
-
- s = DoubleFormatter.stringValue(0.5);
- assertEquals("0.5", s);
-
- s = DoubleFormatter.stringValue(0.1);
- // assertEquals("0.1", s);
-
- s = DoubleFormatter.stringValue(0.00123456789);
- // assertEquals("0.00123456789", s);
-
- s = DoubleFormatter.stringValue(0.0000000000001);
- // assertEquals("0.0000000000001", s);
- }
-
- @Test
- public void testPowersOfTwo() {
- String twos = DoubleFormatter.stringValue(2.0);
- assertEquals("2.0", twos);
-
- twos = DoubleFormatter.stringValue(128.0);
- assertEquals("128.0", twos);
-
- twos = DoubleFormatter.stringValue(1048576.0);
- assertEquals("1048576.0", twos);
-
- twos = DoubleFormatter.stringValue(1073741824.0);
- assertEquals("1.073741824E9", twos);
- }
-
- @Test
- public void testSmallNumbers() {
- for (double d = 1.0; d > 1.0e-200; d *= 0.75) {
- String fs = DoubleFormatter.stringValue(d);
- String vs = String.valueOf(d);
- double rp = Double.valueOf(fs);
- if (d != rp) {
- // System.err.println("differs: "+d+" became "+fs+" then instead: "+rp+" diff: "+(d-rp));
- } else if (! fs.equals(vs)) {
- // System.err.println("string rep differs: "+vs+" became "+fs);
- }
- assertEquals(d, rp, 1.0e-7*d);
- }
- }
-
- @Test
- public void testVerySmallNumbers() {
- for (double d = 1.0; d > 1.0e-200; d *= 0.5) {
- String fs = DoubleFormatter.stringValue(d);
- String vs = String.valueOf(d);
- double rp = Double.valueOf(fs);
- if (d != rp) {
- // System.err.println("differs: "+d+" became "+fs+" then instead: "+rp+" diff: "+(d-rp));
- } else if (! fs.equals(vs)) {
- // System.err.println("string rep differs: "+vs+" became "+fs);
- }
- assertEquals(d, rp, 1.0e-13*d);
- }
- }
-
- @Test
- public void testVeryVerySmallNumbers() {
- for (double d = 1.0e-200; d > 0; d *= 0.5) {
- String fs = DoubleFormatter.stringValue(d);
- String vs = String.valueOf(d);
- double rp = Double.valueOf(fs);
- if (d != rp) {
- // System.err.println("differs: "+d+" became "+fs+" then instead: "+rp+" diff: "+(d-rp));
- } else if (! fs.equals(vs)) {
- // System.err.println("string rep differs: "+vs+" became "+fs);
- }
- assertEquals(d, rp, 1.0e-13*d);
- }
- }
-
- @Test
- public void testVeryBigNumbers() {
- for (double d = 1.0; d < Double.POSITIVE_INFINITY; d *= 2.0) {
- String fs = DoubleFormatter.stringValue(d);
- String vs = String.valueOf(d);
- double rp = Double.valueOf(fs);
- if (d != rp) {
- // System.err.println("differs: "+d+" became "+fs+" then instead: "+rp);
- } else if (! fs.equals(vs)) {
- // System.err.println("string rep differs: "+vs+" became "+fs);
- }
- assertEquals(d, rp, 1.0e-13*d);
- }
-
- assertEquals("1.0E200", String.valueOf(1.0e+200));
-
- String big = DoubleFormatter.stringValue(1.0e+200);
- assertEquals("1.0E200", big);
-
- big = DoubleFormatter.stringValue(1.0e+298);
- assertEquals("1.0E298", big);
-
- big = DoubleFormatter.stringValue(1.0e+299);
- assertEquals("1.0E299", big);
-
- big = DoubleFormatter.stringValue(1.0e+300);
- assertEquals("1.0E300", big);
-
- }
-
- @Test
- public void testRandomNumbers() {
- java.util.Random rgen = new java.util.Random(0xCafeBabe);
- for (int i = 0; i < 123456; i++) {
- double d = rgen.nextDouble();
- }
- }
-
-}
diff --git a/vespajlib/src/test/java/com/yahoo/text/DoubleToStringBenchmark.java b/vespajlib/src/test/java/com/yahoo/text/DoubleToStringBenchmark.java
deleted file mode 100644
index a5925df2caf..00000000000
--- a/vespajlib/src/test/java/com/yahoo/text/DoubleToStringBenchmark.java
+++ /dev/null
@@ -1,124 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.text;
-
-import org.junit.Ignore;
-import org.junit.Test;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Random;
-import java.util.concurrent.CyclicBarrier;
-import java.util.concurrent.TimeUnit;
-
-import static org.junit.Assert.assertEquals;
-
-@SuppressWarnings("deprecation")
-/**
- * @author arnej27959
- */
-public class DoubleToStringBenchmark {
-
- @Test
- @Ignore
- public void benchmarkStringConstruction() throws Exception {
- List<Class<? extends Benchmark.Task>> taskList = Arrays.asList(UseStringValueOf.class,
- UseDoubleFormatter.class,
- UseDoubleFormatter.class,
- UseStringValueOf.class,
- UseStringValueOf.class,
- UseDoubleFormatter.class,
- UseDoubleFormatter.class,
- UseStringValueOf.class,
- UseDoubleFormatter.class,
- UseStringValueOf.class);
-
- int maxThreads = 256;
- int dummy = 0;
- System.out.print("warmup");
- for (Class<? extends Benchmark.Task> taskClass : taskList) {
- dummy += runBenchmark(maxThreads, taskClass);
- System.out.print(".");
- }
- System.out.println(" " + dummy);
-
- System.out.format("%-35s", "");
- for (int numThreads = 1; numThreads <= maxThreads; numThreads *= 2) {
- System.out.format("%13s t ", numThreads);
- }
- System.out.println();
- for (Class<? extends Benchmark.Task> taskClass : taskList) {
- System.out.format("%-35s", taskClass.getSimpleName());
- for (int numThreads = 1; numThreads <= maxThreads; numThreads *= 2) {
- System.out.format("%15d ", runBenchmark(numThreads, taskClass));
- }
- System.out.println();
- }
- }
-
- private long runBenchmark(int numThreads, Class<? extends Benchmark.Task> taskClass) throws Exception {
- return new Benchmark.Builder()
- .setNumIterationsPerThread(80000)
- .setNumThreads(numThreads)
- .setTaskClass(taskClass)
- .build()
- .run();
- }
-
- public static class UseStringValueOf implements Benchmark.Task {
-
- private long timeIt(Random randomGen, int num) {
- long before = System.nanoTime();
-
- String str = null;
- double v = 0.0;
- for (int i = 0; i < num; ++i) {
- v = randomGen.nextDouble() * 1.0e-2;
- str = String.valueOf(v);
- }
-
- long after = System.nanoTime();
- assertEquals(""+v, str);
- return after - before;
- }
-
- @Override
- public long run(CyclicBarrier barrier, int numIterations) throws Exception {
- Random randomGen = new Random(0xDeadBeef);
- barrier.await(600, TimeUnit.SECONDS);
- long t1 = timeIt(randomGen, numIterations / 4);
- long t2 = timeIt(randomGen, numIterations / 2);
- long t3 = timeIt(randomGen, numIterations / 4);
- return t2;
- }
- }
-
- public static class UseDoubleFormatter implements Benchmark.Task {
-
- private long timeIt(Random randomGen, int num) {
- long before = System.nanoTime();
-
- String str = null;
- double v = 0.0;
- for (int i = 0; i < num; ++i) {
- v = randomGen.nextDouble() * 1.0e-2;
- str = DoubleFormatter.stringValue(v);
- }
-
- long after = System.nanoTime();
- // assertEquals(""+v, str);
- return after - before;
- }
-
-
- @Override
- public long run(CyclicBarrier barrier, int numIterations) throws Exception {
- Random randomGen = new Random(0xDeadBeef);
- barrier.await(600, TimeUnit.SECONDS);
- long t1 = timeIt(randomGen, numIterations / 4);
- long t2 = timeIt(randomGen, numIterations / 2);
- long t3 = timeIt(randomGen, numIterations / 4);
- return t2;
- }
- }
-
-}