rpuch commented on a change in pull request #616:
URL: https://github.com/apache/ignite-3/pull/616#discussion_r798505612



##########
File path: 
modules/network/src/test/java/org/apache/ignite/internal/network/SerializationMicroBenchmark.java
##########
@@ -0,0 +1,308 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License 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.
+ */
+
+package org.apache.ignite.internal.network;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.internal.network.serialization.ClassDescriptorFactory;
+import 
org.apache.ignite.internal.network.serialization.ClassDescriptorRegistry;
+import 
org.apache.ignite.internal.network.serialization.marshal.DefaultUserObjectMarshaller;
+import 
org.apache.ignite.internal.network.serialization.marshal.MarshalException;
+import 
org.apache.ignite.internal.network.serialization.marshal.MarshalledObject;
+import 
org.apache.ignite.internal.network.serialization.marshal.UnmarshalException;
+import 
org.apache.ignite.internal.network.serialization.marshal.UserObjectMarshaller;
+import org.jetbrains.annotations.Nullable;
+import org.objenesis.strategy.StdInstantiatorStrategy;
+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.State;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.infra.Blackhole;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+/**
+ * A micro-benchmark of {@link DefaultUserObjectMarshaller}.
+ */
+@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
+@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
+@Fork(3)
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+@State(Scope.Thread)
+public class SerializationMicroBenchmark {
+
+    static TestClass smallObject;
+    static AllTypesMessage mediumObject;
+    static AllTypesMessage largeObject;
+
+    static ClassDescriptorRegistry registry;
+
+    static UserObjectMarshaller userObjectMarshaller;
+
+    static Kryo kryo;
+
+    static byte[] smallSerializedWithUos;
+    static byte[] smallSerializedWithJava;
+    static byte[] smallSerializedWithKryo;
+
+    static byte[] mediumSerializedWithUos;
+    static byte[] mediumSerializedWithJava;
+    static byte[] mediumSerializedWithKryo;
+
+    static byte[] largeSerializedWithUos;
+    static byte[] largeSerializedWithJava;
+    static byte[] largeSerializedWithKryo;
+
+    static {
+        registry = new ClassDescriptorRegistry();
+        var factory = new ClassDescriptorFactory(registry);
+        userObjectMarshaller = new DefaultUserObjectMarshaller(registry, 
factory);
+
+        smallObject = new TestClass(1000, false, 3000);
+        mediumObject = AllTypesMessageGenerator.generate(10, true, false);
+        largeObject = AllTypesMessageGenerator.generate(10, true, true);
+
+        factory.create(smallObject.getClass());
+        factory.create(largeObject.getClass());
+
+        kryo = new Kryo();
+        kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());
+
+        try {
+            smallSerializedWithUos = 
userObjectMarshaller.marshal(smallObject).bytes();
+            mediumSerializedWithUos = 
userObjectMarshaller.marshal(mediumObject).bytes();
+            largeSerializedWithUos = 
userObjectMarshaller.marshal(largeObject).bytes();
+        } catch (MarshalException e) {
+            throw new RuntimeException(e);
+        }
+
+        smallSerializedWithJava = serializeWithJdk(smallObject);
+        mediumSerializedWithJava = serializeWithJdk(mediumObject);
+        largeSerializedWithJava = serializeWithJdk(largeObject);
+
+        smallSerializedWithKryo = serializeWithKryo(smallObject);
+        mediumSerializedWithKryo = serializeWithKryo(mediumObject);
+        largeSerializedWithKryo = serializeWithKryo(largeObject);
+
+        System.out.println("Small Java: " + smallSerializedWithJava.length);
+        System.out.println("Small UOS : " + smallSerializedWithUos.length);
+        System.out.println("Small Kryo: " + smallSerializedWithKryo.length);
+
+        System.out.println("Medium Java: " + mediumSerializedWithJava.length);
+        System.out.println("Medium UOS : " + mediumSerializedWithUos.length);
+        System.out.println("Medium Kryo: " + mediumSerializedWithKryo.length);
+
+        System.out.println("Large Java: " + largeSerializedWithJava.length);
+        System.out.println("Large UOS : " + largeSerializedWithUos.length);
+        System.out.println("Large Kryo: " + largeSerializedWithKryo.length);
+    }
+
+    /**
+     * Runs the benchmark.
+     *
+     * @param args args
+     * @throws Exception if something goes wrong
+     */
+    public static void main(String[] args) throws Exception {
+        Options build = new OptionsBuilder()
+                //.addProfiler("stack")

Review comment:
       Removed the line about  "stack", but I think it makes sense to leave the 
line about "gc" as it is useful in some situations and it's a lot easier to 
uncomment a line than try to recall the correct syntax :)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to