All Downloads are FREE. Search and download functionalities are using the official Maven repository.

convex.benchmarks.OpBenchmark Maven / Gradle / Ivy

There is a newer version: 0.7.15
Show newest version
package  convex.benchmarks;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;

import convex.core.data.ACell;
import convex.core.lang.AOp;
import convex.core.lang.Context;
import convex.core.lang.Core;
import convex.core.lang.Reader;
import convex.core.lang.ops.Constant;
import convex.core.lang.ops.Invoke;

public class OpBenchmark {
	
	static final Context CTX=Benchmarks.context();
	
	private static final ACell runOp(AOp op) {
		return CTX.fork().execute(op).getResult();
	}
	
	static final AOp loopOp=CTX.expandCompile(Reader.read("(dotimes [i 1000])")).getResult();
	@Benchmark
	public void emptyLoop() {
		runOp(loopOp);
	}
	
	static final AOp constantOp=CTX.expandCompile(Reader.read("1")).getResult();
	@Benchmark
	public void constant() {
		runOp(constantOp);
	}
	
	// sum with dynamic core lookup
	static final AOp simpleSum=CTX.expandCompile(Reader.read("(+ 1 2)")).getResult();
	@Benchmark
	public void simpleSum() {
		runOp(simpleSum);
	}
	 
	// sum without dynamic core lookup (much faster!!)
	static final AOp simpleSum2=Invoke.create(Constant.create(Core.PLUS),Constant.of(1L),Constant.of(2));
	@Benchmark
	public void simpleSumPrecompiled() {
		runOp(simpleSum2);
	}
	 


	public static void main(String[] args) throws Exception {
		Options opt = Benchmarks.createOptions(OpBenchmark.class);
		new Runner(opt).run();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy