Coder Social home page Coder Social logo

java-native-benchmark's People

Contributors

zakgof avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

java-native-benchmark's Issues

Use latest open jdk build of panama

Hey there. Would it be possible to rerun this against the latest open jdk 19 build to see if there is any performance changes between JNI and Panama?

Many thanks!

update benchmark to support Panama API in Java 16

Hi,
I've done some work to rewrite your benchmark to support the Panama APIs we have in Java 16 (Foreign Memory Access API [1] and Foreign Linker API [2]) - the results I've got are:

Benchmark                                   Mode  Cnt Score     Error  Units
JmhCallOnly.bridj                           avgt   50   279.563 ▒   4.312  ns/op
JmhCallOnly.jna                             avgt   50   826.049 ▒ 11.840  ns/op
JmhCallOnly.jna_direct                      avgt   50   934.675 ▒ 13.662  ns/op
JmhCallOnly.jni_javacpp                     avgt   50    36.899 ▒   0.618  ns/op
JmhCallOnly.jnr                             avgt   50   233.757 ▒   3.090  ns/op
JmhCallOnly.panama                          avgt   50    30.332 ▒   0.386  ns/op
JmhGetSystemTimeSeconds.bridj               avgt   50  1306.806 ▒ 131.925  ns/op
JmhGetSystemTimeSeconds.java_calendar       avgt   50   136.437 ▒   3.949  ns/op
JmhGetSystemTimeSeconds.java_date           avgt   50    50.450 ▒   0.750  ns/op
JmhGetSystemTimeSeconds.java_localdatetime  avgt   50    58.232 ▒   1.456  ns/op
JmhGetSystemTimeSeconds.jna                 avgt   50  3194.622 ▒ 216.633  ns/op
JmhGetSystemTimeSeconds.jnaDirect           avgt   50  3227.971 ▒ 193.953  ns/op
JmhGetSystemTimeSeconds.jni_javacpp         avgt   50   418.683 ▒   5.789  ns/op
JmhGetSystemTimeSeconds.jnr                 avgt   50   327.486 ▒   7.548  ns/op
JmhGetSystemTimeSeconds.panama              avgt   50   390.615 ▒   3.987  ns/op 

Would it be possible to update the benchmark?

Here's the source code I've used for the Panama benchmark:

package com.zakgof.jnbenchmark.panama;

import java.lang.invoke.*;
import jdk.incubator.foreign.*;
import jdk.incubator.foreign.MemoryLayout.*;

import static jdk.incubator.foreign.CLinker.*;

public class PanamaBenchmark {

	static final MemoryLayout SYSTEMTIME = MemoryLayout.ofStruct(
			C_SHORT.withName("wYear"),
			C_SHORT.withName("wMonth"),
			C_SHORT.withName("wDayOfWeek"),
			C_SHORT.withName("wDay"),
			C_SHORT.withName("wHour"),
			C_SHORT.withName("wMinute"),
			C_SHORT.withName("wSecond"),
			C_SHORT.withName("wMilliseconds")
	);

	// var handle

	final static VarHandle wSecond = SYSTEMTIME.varHandle(short.class, PathElement.groupElement("wSecond"));

	// method handle

	final static MethodHandle GetSystemTime = CLinker.getInstance().downcallHandle(
		LibraryLookup.ofDefault().lookup("GetSystemTime").get(),
		MethodType.methodType(void.class, MemoryAddress.class),
		FunctionDescriptor.ofVoid(C_POINTER)
	);

	final MemorySegment systemtime_shared;

	public PanamaBenchmark() {
		this.systemtime_shared = MemorySegment.allocateNative(SYSTEMTIME);
	}

	public short all() {
		try (MemorySegment systemtime = MemorySegment.allocateNative(SYSTEMTIME)) {
			GetSystemTime.invokeExact(systemtime.address());
			return (short) wSecond.get(systemtime);
		} catch (Throwable ex) {
			throw new AssertionError(ex);
		}
	}

	public void callOnly() {
		try {
			GetSystemTime.invokeExact(systemtime_shared.address());
		} catch (Throwable ex) {
			throw new AssertionError(ex);
		}
	}
}

I hope this helps.

[1] - https://openjdk.java.net/jeps/393
[2] - https://openjdk.java.net/jeps/389

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.