Skip to content

Instantly share code, notes, and snippets.

@pcn
Last active December 31, 2015 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcn/7937204 to your computer and use it in GitHub Desktop.
Save pcn/7937204 to your computer and use it in GitHub Desktop.
Clojure devs recommend writing with spit. Which is really inefficient.
```
carbon-relaj.core=> (time
#_=> (doseq [c (range 10000)]
#_=> (spit "/tmp/spit-file" (str c "\n"))))
"Elapsed time: 8613.006 msecs"
nil
carbon-relaj.core=>
carbon-relaj.core=> (time
#_=> (let [fname "/tmp/with-open"]
#_=> (with-open [wr-file (clojure.java.io/writer fname)]
#_=> (doseq [c (range 10000)]
#_=> (.write wr-file (str c "\n"))))))
"Elapsed time: 4.991 msecs"
nil
```
There's no real surprise here, it just confirms that there's no secret sauce to
make writing to the file fast as long as the context of the write is to the same file :(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment