Git Product home page Git Product logo

Comments (2)

jgpc42 avatar jgpc42 commented on June 7, 2024

Hi, thanks for opening this issue.

I've never used boot, so this took some time to figure out. It looks like it has to do with how it dynamically manages the class path.

For example, if I lein repl or clj into the example project and evaluate (System/getProperty "java.class.path"), I get the expected entries including jmh-core-1.19.jar, etc.

If I use boot repl however, the property is missing the expected entries and is just a single path. A cursory search yielded this issue, which looks like it might be related.

You can "fix" boot by altering the example REPL session from the README like so:

(require '[jmh.core :as jmh]
         '[clojure.java.io :as io]
         '[clojure.edn :as edn])

(def bench-env
  (-> "benchmarks.edn" io/resource slurp edn/read-string))

;; The class path used for dynamic java compilation and JMH forks
(def boot-classpath 
  (str (System/getProperty "fake.class.path")
       java.io.File/pathSeparator
       *compile-path*))

(System/setProperty "java.class.path" boot-classpath)

(jmh/run bench-env {:type :quick})

It seems the fake.class.path property is the canonical workaround (?) when using boot with libraries like jmh-clojure and others that expect standard class path semantics.

Again, I have no real experience with boot, so I'd appreciate any feedback from boot users on how to better support it with a more idiomatic solution.

from jmh-clojure.

giorgio-v avatar giorgio-v commented on June 7, 2024

Yes, it seems the correct way to handle issues like this. FWIW, I’ve also tried to define a task. Something like:

(deftask jmh
  "Run JMH benchmarks"
  [c benchmark-configuration VALUE str "resource EDN file with benchmark configuration"]
  (let [bench-env (-> benchmark-configuration
                        clojure.java.io/resource
                        slurp
                        clojure.edn/read-string)
          ;; to be extracted?
          bench-opts
          {:type      :quick
           :params    {:count [31 100000]}
           :profilers ["gc"]}]
    (fn [continue]
      (fn [event]
        (System/setProperty "java.class.path"
                            (str (System/getProperty "fake.class.path")
                                 java.io.File/pathSeparator
                                 *compile-path*))
        (jmh/run bench-env bench-opts)
        (continue event)))))

But it fails. Whereas I can call a simple function like this:

(defn run-benchmarks! [benchmark-configuration bench-opts]
  (System/setProperty "java.class.path"
                      (str (System/getProperty "fake.class.path")
                           java.io.File/pathSeparator
                           *compile-path*))
  (jmh/run (-> benchmark-configuration
               clojure.java.io/resource
               slurp
               clojure.edn/read-string)
    bench-opts))

Anyway, I think I can close this? Thank you for the quick reply!

from jmh-clojure.

Related Issues (9)

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.