Skip to content

Instantly share code, notes, and snippets.

View isicju's full-sized avatar

Dmitry Egorov isicju

View GitHub Profile
@isicju
isicju / currentTimeMillisBenchmarking.java
Last active October 25, 2017 18:13
old-fashioned benchmarking
long before = System.currentTimeMillis();
doMagic();
long now = System.currentTimeMillis();
System.out.println("Seconds elapsed: " + (now-before)/1000F + " seconds." );
@isicju
isicju / jhmjavahelloworld.java
Created October 25, 2017 18:36
making great benchmarking
package org.sample;
import org.openjdk.jmh.annotations.*;
import java.util.concurrent.TimeUnit;
public class MyBenchmark {
@Benchmark@BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.MICROSECONDS)
public void testMethod() {
doMagic();
}
public static void doMagic() {
@isicju
isicju / jhmjavahelloworld.java
Created October 25, 2017 18:36
making great benchmarking
package org.sample;
import org.openjdk.jmh.annotations.*;
import java.util.concurrent.TimeUnit;
public class MyBenchmark {
@Benchmark@BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.MICROSECONDS)
public void testMethod() {
doMagic();
}
public static void doMagic() {
@isicju
isicju / jhmjavahelloworld.java
Created October 25, 2017 18:36
making great benchmarking
package org.sample;
import org.openjdk.jmh.annotations.*;
import java.util.concurrent.TimeUnit;
public class MyBenchmark {
@Benchmark@BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.MICROSECONDS)
public void testMethod() {
doMagic();
}
public static void doMagic() {
@Benchmark
@BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.MICROSECONDS)
@Fork(value = 1)
@Warmup(iterations = 2)
@Measurement(iterations = 5)
public void testMethod() {
doMagic();
}
Options opt = new OptionsBuilder()
.include(JMHSample_01_HelloWorld.class.getSimpleName())
.warmupIterations(2)
.measurementIterations(5)
.forks(1)
.shouldDoGC(true)
.build();
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion>
<groupId>hellodocker</groupId><artifactId>hellodocker</artifactId><version>1.0-SNAPSHOT</version>
<dependencies><dependency><groupId>com.sparkjava</groupId><artifactId>spark-core</artifactId><version>2.0.0</version></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><version>2.4</version><configuration><finalName>sparkexample</finalName><archive><manifest><addClasspath>true</addClasspath><mainClass>sparkexample.Hello</mainClass><classpathPrefix>dependency-jars/</classpathPrefix></manifest></archive></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.1</version><conf
package sparkexample;
import spark.Spark;
import static spark.Spark.get;
public class Hello {
public static void main(String[] args) {
Spark.staticFileLocation("/public");
java -jar target/sparkexample-jar-with-dependencies.jar
mvn clean install