Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 67 additions & 15 deletions src/jmh/java/io/jawk/jrt/JRTCompare2Benchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ public class JRTCompare2Benchmark {
private Object stringLeft;
private Object stringRightEqual;
private Object stringRightGreater;
private Object numericStringLeft;
private Object numericStringRightEqual;
private Object numericStringRightGreater;
private Object plainNumericStringLeft;
private Object plainNumericStringRightEqual;
private Object plainNumericStringRightGreater;
private Object nonNumericString;
private Object strNumLeft;
private Object strNumRightEqual;
private Object strNumRightGreater;
private Object nonNumericStrNum;

/**
* Initializes benchmark operands as mutable state fields so the benchmark body
Expand All @@ -78,10 +82,14 @@ public void setup() {
this.stringLeft = "alpha";
this.stringRightEqual = "alpha";
this.stringRightGreater = "bravo";
this.numericStringLeft = "123";
this.numericStringRightEqual = "123.0";
this.numericStringRightGreater = "456";
this.plainNumericStringLeft = "123";
this.plainNumericStringRightEqual = "123.0";
this.plainNumericStringRightGreater = "456";
this.nonNumericString = "2x";
this.strNumLeft = new StrNum("123");
this.strNumRightEqual = new StrNum("123.0");
this.strNumRightGreater = new StrNum("456");
this.nonNumericStrNum = new StrNum("2x");
}

/**
Expand Down Expand Up @@ -155,33 +163,66 @@ public boolean stringLessThan() {
}

/**
* Measures equality for two numeric string operands.
* Measures equality for two plain numeric-looking {@link String} operands.
*
* @return the comparison result
*/
@Benchmark
public boolean numericStringEquals() {
return JRT.compare2(this.numericStringLeft, this.numericStringRightEqual, 0);
public boolean plainNumericStringEquals() {
return JRT.compare2(this.plainNumericStringLeft, this.plainNumericStringRightEqual, 0);
}

/**
* Measures less-than comparison for two numeric string operands.
* Measures less-than comparison for two plain numeric-looking {@link String}
* operands.
*
* @return the comparison result
*/
@Benchmark
public boolean numericStringLessThan() {
return JRT.compare2(this.numericStringLeft, this.numericStringRightGreater, -1);
public boolean plainNumericStringLessThan() {
return JRT.compare2(this.plainNumericStringLeft, this.plainNumericStringRightGreater, -1);
}

/**
* Measures equality for a boxed {@link Long} and a numeric string operand.
* Measures equality for a boxed {@link Long} and a plain numeric-looking
* {@link String} operand.
*
* @return the comparison result
*/
@Benchmark
public boolean mixedLongNumericStringEquals() {
return JRT.compare2(this.longLeft, this.numericStringRightEqual, 0);
public boolean mixedLongPlainNumericStringEquals() {
return JRT.compare2(this.longLeft, this.plainNumericStringRightEqual, 0);
}

/**
* Measures equality for two input-derived numeric string operands.
*
* @return the comparison result
*/
@Benchmark
public boolean strNumEquals() {
return JRT.compare2(this.strNumLeft, this.strNumRightEqual, 0);
}

/**
* Measures less-than comparison for two input-derived numeric string operands.
*
* @return the comparison result
*/
@Benchmark
public boolean strNumLessThan() {
return JRT.compare2(this.strNumLeft, this.strNumRightGreater, -1);
}

/**
* Measures equality for a boxed {@link Long} and an input-derived numeric
* string operand.
*
* @return the comparison result
*/
@Benchmark
public boolean mixedLongStrNumEquals() {
return JRT.compare2(this.longLeft, this.strNumRightEqual, 0);
}

/**
Expand All @@ -194,4 +235,15 @@ public boolean mixedLongNumericStringEquals() {
public boolean mixedLongNonNumericStringLessThan() {
return JRT.compare2(this.longLeft, this.nonNumericString, -1);
}

/**
* Measures fallback string comparison for a numeric operand and a nonnumeric
* input-derived string.
*
* @return the comparison result
*/
@Benchmark
public boolean mixedLongNonNumericStrNumLessThan() {
return JRT.compare2(this.longLeft, this.nonNumericStrNum, -1);
}
}
59 changes: 59 additions & 0 deletions src/jmh/java/io/jawk/jrt/JRTHotPathBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public class JRTHotPathBenchmark {
private Object zeroLong;
private Object zeroDouble;
private Object zeroString;
private Object zeroStrNum;
private Object nonZeroStrNum;
private Object nonNumericStrNum;
private Object uninitialized;
private double integralDouble;
private double fractionalDouble;
Expand All @@ -87,6 +90,9 @@ public void setup() {
this.zeroLong = Long.valueOf(0L);
this.zeroDouble = Double.valueOf(0.0D);
this.zeroString = "0";
this.zeroStrNum = new StrNum("0");
this.nonZeroStrNum = new StrNum("123");
this.nonNumericStrNum = new StrNum("2x");
this.uninitialized = new UninitializedObject();
this.integralDouble = 123456789D;
this.fractionalDouble = 123456.75D;
Expand Down Expand Up @@ -166,6 +172,28 @@ public double toDoubleNonNumericString() {
return JRT.toDouble(this.nonNumericString);
}

/**
* Measures {@link JRT#toDouble(Object)} for an input-derived fully numeric
* string.
*
* @return converted value
*/
@Benchmark
public double toDoubleStrNumNumeric() {
return JRT.toDouble(this.nonZeroStrNum);
}

/**
* Measures {@link JRT#toDouble(Object)} for an input-derived numeric-prefix
* string.
*
* @return converted value
*/
@Benchmark
public double toDoubleStrNumNumericPrefix() {
return JRT.toDouble(this.nonNumericStrNum);
}

/**
* Measures {@link JRT#toDouble(Object)} for an empty string.
*
Expand Down Expand Up @@ -336,6 +364,37 @@ public boolean toBooleanStringZero() {
return this.jrt.toBoolean(this.zeroString);
}

/**
* Measures {@link JRT#toBoolean(Object)} for an input-derived zero string.
*
* @return converted value
*/
@Benchmark
public boolean toBooleanStrNumZero() {
return this.jrt.toBoolean(this.zeroStrNum);
}

/**
* Measures {@link JRT#toBoolean(Object)} for an input-derived non-zero string.
*
* @return converted value
*/
@Benchmark
public boolean toBooleanStrNumNonZero() {
return this.jrt.toBoolean(this.nonZeroStrNum);
}

/**
* Measures {@link JRT#toBoolean(Object)} for an input-derived nonnumeric
* string.
*
* @return converted value
*/
@Benchmark
public boolean toBooleanStrNumNonNumeric() {
return this.jrt.toBoolean(this.nonNumericStrNum);
}

/**
* Measures {@link JRT#toBoolean(Object)} for an uninitialized runtime value.
*
Expand Down
12 changes: 1 addition & 11 deletions src/main/java/io/jawk/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,17 +382,7 @@ private static void addVariable(AwkSettings settings, String keyValue) {
}
String name = m.group(1);
String valueString = m.group(2);
Object value;
try {
value = Integer.parseInt(valueString);
} catch (NumberFormatException nfe) {
try {
value = Double.parseDouble(valueString);
} catch (NumberFormatException nfe2) {
value = valueString;
}
}
settings.putVariable(name, value);
settings.putVariable(name, valueString);
}

/**
Expand Down
Loading
Loading