Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roughly measure function performance #6

Open
Lambeaux opened this issue Apr 25, 2020 · 0 comments
Open

Roughly measure function performance #6

Lambeaux opened this issue Apr 25, 2020 · 0 comments
Labels
context/needs-refinement This issue needs more details, definition of done, or acceptance criteria before it can be worked type/idea General improvement that doesn't fit any of the other types

Comments

@Lambeaux
Copy link
Contributor

Having an easy way to measure the speed at which an arbitrary function executes would be handy for measuring the impact of pmap and similar multithreaded optimizations. This can be either a function or a macro. One crude attempt at the function approach is below.

(defn with-time-log
  ;; Unable to resolve var: f in this context
  "Wraps execution of function f in order to measure f's execution time."
  [f & args]
  (let [#_f-meta #_(meta (var f))
        #_f-name #_(if f-meta (:name f-meta) "-inaccessible-name-")
        start (System/currentTimeMillis)
        result (apply f args)
        end (System/currentTimeMillis)]
    (do start
        result
        end
        (println (str "Time elapsed for fn"
                      #_f-name
                      ": "
                      (float (/ (- end start) 1000))
                      " ms"))
        result)))

Note several problems:

  • Arbitrary Clojure Vars cannot be passed around or accessed by just anyone so obtaining the function name demands a macro so access is conducted through the same ns all the time; this is the issue with f-meta and f-name and would make reporting easier with the function name.
  • Clojure is lazy by default and after some fiddling, even with forcing side effects, the time is logging way too quickly and is not correct; probably a simple fix but need to revisit later.
@Lambeaux Lambeaux added the type/enhancement Something that isn't working - this is a feature that needs more polish or quality control label Apr 25, 2020
@Lambeaux Lambeaux added context/needs-refinement This issue needs more details, definition of done, or acceptance criteria before it can be worked type/idea General improvement that doesn't fit any of the other types and removed type/enhancement Something that isn't working - this is a feature that needs more polish or quality control labels Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
context/needs-refinement This issue needs more details, definition of done, or acceptance criteria before it can be worked type/idea General improvement that doesn't fit any of the other types
Projects
None yet
Development

No branches or pull requests

1 participant