Skip to content

Instantly share code, notes, and snippets.

@jgpc42
Last active August 14, 2020 18:26
Show Gist options
  • Save jgpc42/a694c8b4255ed332dac38428bd4e0546 to your computer and use it in GitHub Desktop.
Save jgpc42/a694c8b4255ed332dac38428bd4e0546 to your computer and use it in GitHub Desktop.

Revisions

  1. jgpc42 revised this gist Aug 14, 2020. No changes.
  2. jgpc42 created this gist Aug 14, 2020.
    10 changes: 10 additions & 0 deletions core.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    ;; 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))
    27 changes: 27 additions & 0 deletions jmh.edn
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    ;; 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}}}
    8 changes: 8 additions & 0 deletions project.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    (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]}})
    8 changes: 8 additions & 0 deletions run.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    #! /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}'