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
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ plugins {
// Without `apply false`, the plugin is automatically applied to the main "jar" task, which somehow interferes with
// the "spotbugsMain" task, causing it to fail. Instead, we will create a separate task to generate the bundle info.
id("biz.aQute.bnd.builder") version "6.4.0" apply false

id("me.champeau.jmh") version "0.7.2"
}

jacoco {
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ plugins {

rootProject.name = "ion-java"
include("ion-java-cli")
include("jmh")
101 changes: 101 additions & 0 deletions src/jmh/java/com/amazon/ion/IonValueGetTypeBenchmark.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package com.amazon.ion;


import com.amazon.ion.system.IonSystemBuilder;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;

import java.io.IOException;
import java.nio.file.Paths;
import java.util.concurrent.TimeUnit;

@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Fork(1)
@Warmup(iterations = 3, time = 10, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 10, timeUnit = TimeUnit.SECONDS)
@State(Scope.Benchmark)
public class IonValueGetTypeBenchmark {

private static final IonSystem SYSTEM = IonSystemBuilder.standard().build();

private final IonBool bool = SYSTEM.newBool(false);
private final IonInt integer = SYSTEM.newInt(123);
private final IonNull ionNull = SYSTEM.newNull();
private final IonFloat ionFloat = SYSTEM.newFloat(42);
private final IonDecimal ionDecimal = SYSTEM.newDecimal(1.23);
private final IonString string = SYSTEM.newString("abc");
private final IonSymbol symbol = SYSTEM.newSymbol("def");
private final IonBlob blob = SYSTEM.newBlob(new byte[]{});
private final IonClob clob = SYSTEM.newClob(new byte[]{});
private final IonStruct struct = SYSTEM.newEmptyStruct();
private final IonList list = SYSTEM.newEmptyList();
private final IonSexp sexp = SYSTEM.newEmptySexp();
private final IonDatagram dg = SYSTEM.newDatagram();

@Benchmark
public int ionValueGetType() {
return integer.getType().ordinal() +
bool.getType().ordinal() +
ionNull.getType().ordinal() +
ionFloat.getType().ordinal() +
ionDecimal.getType().ordinal() +
string.getType().ordinal() +
symbol.getType().ordinal() +
blob.getType().ordinal() +
clob.getType().ordinal() +
struct.getType().ordinal() +
list.getType().ordinal() +
sexp.getType().ordinal() +
dg.getType().ordinal();
}

private final IonDatagram container;
private Blackhole bh;

public IonValueGetTypeBenchmark() {
try {
container = SYSTEM.getLoader().load(Paths.get("ion-tests/iontestdata/good/message2.ion").toFile());
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@Setup
public void setup(Blackhole bh) {
this.bh = bh;
}

@Benchmark
public void getTypeContainer() {
getTypeRecursive(container);
}

public void getTypeRecursive(IonContainer container) {
bh.consume(container.getType());
for (IonValue child : container) {
IonType type = child.getType();
bh.consume(type);
switch (type) {
case STRUCT:
case LIST:
case SEXP:
getTypeRecursive((IonContainer) child);
break;
default:
break;
}
}
}
}
19 changes: 3 additions & 16 deletions src/main/java/com/amazon/ion/impl/lite/IonBlobLite.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2007-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package com.amazon.ion.impl.lite;

import com.amazon.ion.IonBlob;
Expand Down Expand Up @@ -67,7 +54,7 @@ int scalarHashCode() {
}

@Override
public IonType getType()
public IonType getTypeSlow()
{
return IonType.BLOB;
}
Expand Down
19 changes: 3 additions & 16 deletions src/main/java/com/amazon/ion/impl/lite/IonBoolLite.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2007-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package com.amazon.ion.impl.lite;

import com.amazon.ion.IonBool;
Expand Down Expand Up @@ -68,7 +55,7 @@ public IonBoolLite clone()
}

@Override
public IonType getType()
public IonType getTypeSlow()
{
return IonType.BOOL;
}
Expand Down
19 changes: 3 additions & 16 deletions src/main/java/com/amazon/ion/impl/lite/IonClobLite.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2007-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package com.amazon.ion.impl.lite;

import com.amazon.ion.IonClob;
Expand Down Expand Up @@ -70,7 +57,7 @@ int scalarHashCode() {
}

@Override
public IonType getType()
public IonType getTypeSlow()
{
return IonType.CLOB;
}
Expand Down
19 changes: 3 additions & 16 deletions src/main/java/com/amazon/ion/impl/lite/IonDatagramLite.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2007-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package com.amazon.ion.impl.lite;

import static com.amazon.ion.SystemSymbols.ION_1_0;
Expand Down Expand Up @@ -386,7 +373,7 @@ public IonSystemLite getSystem()
}

@Override
public IonType getType()
public IonType getTypeSlow()
{
return IonType.DATAGRAM;
}
Expand Down
19 changes: 3 additions & 16 deletions src/main/java/com/amazon/ion/impl/lite/IonDecimalLite.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2007-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package com.amazon.ion.impl.lite;

import com.amazon.ion.Decimal;
Expand Down Expand Up @@ -105,7 +92,7 @@ int scalarHashCode()
}

@Override
public IonType getType()
public IonType getTypeSlow()
{
return IonType.DECIMAL;
}
Expand Down
19 changes: 3 additions & 16 deletions src/main/java/com/amazon/ion/impl/lite/IonFloatLite.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2007-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package com.amazon.ion.impl.lite;

import com.amazon.ion.Decimal;
Expand Down Expand Up @@ -76,7 +63,7 @@ int scalarHashCode()
}

@Override
public IonType getType()
public IonType getTypeSlow()
{
return IonType.FLOAT;
}
Expand Down
19 changes: 3 additions & 16 deletions src/main/java/com/amazon/ion/impl/lite/IonIntLite.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2007-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package com.amazon.ion.impl.lite;

import com.amazon.ion.IntegerSize;
Expand Down Expand Up @@ -107,7 +94,7 @@ int scalarHashCode()
}

@Override
public IonType getType()
public IonType getTypeSlow()
{
return IonType.INT;
}
Expand Down
19 changes: 3 additions & 16 deletions src/main/java/com/amazon/ion/impl/lite/IonListLite.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2007-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package com.amazon.ion.impl.lite;

import com.amazon.ion.ContainedValueException;
Expand Down Expand Up @@ -81,7 +68,7 @@ int hashSignature() {
}

@Override
public IonType getType()
public IonType getTypeSlow()
{
return IonType.LIST;
}
Expand Down
19 changes: 3 additions & 16 deletions src/main/java/com/amazon/ion/impl/lite/IonNullLite.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2007-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package com.amazon.ion.impl.lite;

import com.amazon.ion.IonNull;
Expand Down Expand Up @@ -58,7 +45,7 @@ public IonNullLite clone()
}

@Override
public IonType getType()
public IonType getTypeSlow()
{
return IonType.NULL;
}
Expand Down
Loading