Some things you could do that would probably speed this code up:
1) Instead of mapping your chars
to char-val
, just do direct value comparisons between the characters. This is faster for the same reason it would faster in Java.
2) You repeatedly use str
to convert single-character values to full-fledged strings. Again, consider using the character values directly. Again, object creation is slow, same as in Java.
3) You should replace process-content
with clojure.core/frequencies
. Perhaps inspect frequencies
source to see how it is faster.
4) If you must update a (hash-map)
in a loop, use transient
. See: http://clojuredocs.org/clojure_core/clojure.core/transient
Also note that (hash-map)
returns a PersistentArrayMap
, so you are creating new instances with each call to update-in
- hence slow and why you should use transients.
5) This is your friend: (set! *warn-on-reflection* true)
- You have quite a bit of reflection that could benefit from type hints
Reflection warning, scratch.clj:10:13 - call to isFile can't be resolved.
Reflection warning, scratch.clj:13:16 - call to getNumericValue can't be resolved.
Reflection warning, scratch.clj:19:11 - call to getNumericValue can't be resolved.
Reflection warning, scratch.clj:26:9 - call to isSpaceChar can't be resolved.
Reflection warning, scratch.clj:30:47 - call to toLowerCase can't be resolved.
Reflection warning, scratch.clj:48:24 - reference to field getPath can't be resolved.
Reflection warning, scratch.clj:48:24 - reference to field getPath can't be resolved.