9d49cde8ca14f16a852153b3fbc62d1825d0e4b1 — Dominic Monroe 1 year, 11 months ago 14f2e9b
Add threshold CLI flag
2 files changed, 21 insertions(+), 7 deletions(-)

M src/io/dominic/slow_namespace_clj/core.clj
M README.md => README.md +6 -2
@@ 16,18 16,22 @@ Add an alias to `~/.clojure/deps.edn`

Then you can scan for just dependencies of your project, by specifying the
directories from your project
directories from your project.
By default, namespaces faster than 0.1msecs are hidden, which can be changed with the `-t` flag.

# Main project
$ clojure -A:user/slow-namespace-clj src
# For development
$ clojure -A:dev:user/slow-namespace-clj src dev test
# Change threshold
$ clojure -A:user/slow-namespace-clj -t 100 src
# Dirs starting with - (very rare)
$ clojure -A:user/slow-namespace-clj -t 100 -- -src

## Output

By default, namespaces faster than 0.1msecs are hidden.
Namespaces are sorted from fastest to slowest.

A section called "groups" prints out the namespace prefixes and their speeds, to help identify slow libraries.

M src/io/dominic/slow_namespace_clj/core.clj => src/io/dominic/slow_namespace_clj/core.clj +15 -5
@@ 104,8 104,18 @@
       (println group ":" ttr "msecs")))))

(defn -main
  [& dirs]
  (binding [*safe* true]
    (if (seq dirs)
      (run {:graph (ns-graph (map #(java.io.File. %) dirs))})
  [& args]
  (let [{:keys [dirs threshold]}
        (loop [opts {} args args]
          (if (seq args)
            (case (first args)
              "--" (update opts :dirs concat (rest args))
              "-t" (recur (assoc opts :threshold (Double/parseDouble (second args))) (drop 2 args))
              (recur (update opts :dirs conj (first args)) (rest args)))
    (binding [*safe* true]
      (run (cond-> {}
             (seq dirs)
             (assoc :graph (ns-graph (map #(java.io.File. %) dirs)))
             (assoc :threshold threshold))))))