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

display execution time #157

Open
daslu opened this issue Sep 13, 2024 · 3 comments
Open

display execution time #157

daslu opened this issue Sep 13, 2024 · 3 comments

Comments

@daslu
Copy link
Member

daslu commented Sep 13, 2024

Zulip discussion: https://clojurians.zulipchat.com/#narrow/stream/422115-clay-dev/topic/Idea.3A.20display.20execution.20time

@whatacold
Copy link
Member

@daslu Hi, my initial thought was that we can capture the output just like with-out-str, and I tweaked the complete function to concat the output and the eval result like this:

-(defn complete [{:as note
-                 :keys [comment? code form value]}]
+(defn complete
+  "Complete `note` by evaluating its `code` or `form`."
+  [{:as note
+    :keys [comment? code form value]}]
   (-> (if (or value comment?)
         note
-        (assoc note
-          :value (cond code (-> code
-                                read-string
-                                eval
-                                deref-if-needed)
-                       form (-> form
-                                eval
-                                deref-if-needed))))
+        (let [new-out (new java.io.StringWriter)]
+          (binding [*out* new-out]
+            (assoc note
+                   :value (->> (cond code (-> code
+                                             read-string
+                                             eval
+                                             deref-if-needed)
+                                    form (-> form
+                                             eval
+                                             deref-if-needed))
+                               (str new-out "\n")
+                               )))))
       (cond-> (not comment?)

It turned out this doesn't work as the concat'ed string will be treated as the whole value, that is, "\"Elapsed time: 0.027495 msecs\"\n\n6" will be the value for (time (+ 1 2 3)).

What do you think will be a better way to achieve the goal? Thanks.

@daslu
Copy link
Member Author

daslu commented Sep 22, 2024

Thanks for looking into this.

Probably we should measure times ourselves, and probably this should happen in the scicloj.clay.v2.make namespace.

Anyway, first, we should define the goal better.
We should clarify what times should actually be measured (evaluation? rendering? etc.) in various workflows.

@whatacold
Copy link
Member

whatacold commented Sep 22, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants