Skip to content

Instantly share code, notes, and snippets.

@jgpc42
Last active August 14, 2020 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgpc42/a694c8b4255ed332dac38428bd4e0546 to your computer and use it in GitHub Desktop.
Save jgpc42/a694c8b4255ed332dac38428bd4e0546 to your computer and use it in GitHub Desktop.
jmh-clojure uberjar example
;; src/demo/core.clj
(ns demo.core
(:require [clojure.core.async :as async]))
(defn blocking-put [ch]
(async/>!! ch 42))
(defn blocking-take [ch]
(async/<!! ch))
;; resources/jmh.edn
{:benchmarks
[{:name :put
:fn demo.core/blocking-put
:args [:chan]
:options {:threads 3}}
{:name :take
:fn demo.core/blocking-take
:args [:chan]}]
:states
{:chan
{:scope :group :fn clojure.core.async/chan :args [:chan-n]}}
:params
{:chan-n [1]}
:options
{:async
{:group :g
:timeout [1 :sec]
:mode :average
:output-time-unit :ns
:fork {:count 1 :warmups 0}
:measurement 2
:warmup 2}}}
(defproject demo "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.10.1"]
[org.clojure/core.async "1.3.610"]]
:plugins [[lein-jmh "0.3.0-SNAPSHOT"]]
:profiles {:jmh {:jvm-opts []}
:uberjar {:dependencies [[jmh-clojure/task "0.1.0-SNAPSHOT"]]
:main jmh.main
:aot [jmh.main]}})
#! /usr/bin/env bash
set -e
lein uberjar
mkdir -p target/tmp/classes && cd target/tmp
cp=classes:../demo-0.1.0-SNAPSHOT-standalone.jar
java -Dfile.encoding=UTF-8 -cp "$cp" jmh.main '{:fail-on-error false, :format [:table :pprint], :type :async, :status true, :verbose true}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment