Re: Help me understand what part of this code is slow, and how to make it faster?

2016-11-16 Thread James Reeves
On 16 November 2016 at 03:39, Didier wrote: > > Currently, this takes about 30s in Clojure, while it only takes around 3s > for OCaml, Rust and F#. > > From what I see, the differences between my code and theirs are: > >- Lack of a Point struct, I'm just using a vector. >- They use a mutab

Re: Help me understand what part of this code is slow, and how to make it faster?

2016-11-16 Thread Jason Felice
I'll bet the atom accesses dominate the computation. They are a part of Clojures software transactional memory (STM) and have a cost. Something like this (untested) should be faster: (->> (iterate neighbors #{p}) (drop 1999) first) neighbors could be: (into #{} (for [[id jd] [[-1 0] [+1 0] [0

Re: Help me understand what part of this code is slow, and how to make it faster?

2016-11-16 Thread Alex Miller
On Wednesday, November 16, 2016 at 8:10:27 AM UTC-6, Jason Felice wrote: > > I'll bet the atom accesses dominate the computation. They are a part of > Clojures software transactional memory (STM) and have a cost. > Atoms don't use the STM and if used in a single-threaded context like this, th

Re: Spec validation cache?

2016-11-16 Thread Alex Miller
Maybe you don't need to instrument *all* functions in development? Alternatively, you could instrument and provide simpler replacement specs to improve speed. For example, an fspec arg could be replaced with ifn?. On Tuesday, November 15, 2016 at 10:29:34 PM UTC-6, Gal Dolber wrote: > > I'm ha

Re: Help me understand what part of this code is slow, and how to make it faster?

2016-11-16 Thread Alex Miller
In general, any benchmark code using math should be aware of boxing (old post here: http://insideclojure.org/2014/12/15/warn-on-boxed/). I would recommend doing the work to leverage primitive longs and unchecked math. Generally this makes numeric code like this about 2 orders of magnitude faste

Re: How to check type of generic parameter with spec?

2016-11-16 Thread Alex Miller
On Tuesday, November 15, 2016 at 10:11:34 PM UTC-6, Eunmin Kim wrote: > > Hi! I had a question while reading Functional Programming in Scala book. > > The following code is Exercise 2: > > // Exercise 2: Implement a polymorphic function to check whether > // an `Array[A]` is sorted > > def isSort

Re: How to check type of generic parameter with spec?

2016-11-16 Thread Eunmin Kim
Thanks for the reply. :) On Wednesday, November 16, 2016 at 11:44:50 PM UTC+9, Alex Miller wrote: > > > > On Tuesday, November 15, 2016 at 10:11:34 PM UTC-6, Eunmin Kim wrote: >> >> Hi! I had a question while reading Functional Programming in Scala book. >> >> The following code is Exercise 2: >>

Re: Help me understand what part of this code is slow, and how to make it faster?

2016-11-16 Thread Michael Gardner
Below is the fastest version I tested, using ideas from the various responses in this thread. It runs in ~4s on my machine, compared with ~27s for the original version. The biggest win by far was from James Reeves' suggestion of switching to Java's mutable HashSet. I'm not sure why; I'd thought

Re: [ANN] Clojure Programming Cookbook

2016-11-16 Thread James Gatannah
Congrats! On Monday, November 14, 2016 at 9:09:01 PM UTC-6, Nicolas Modrzyk wrote: > > Hi Clojure people, > > So after one year and 23 days, (that would be 388 days) the IT book I was > working on with Makoto (merci!) finally got published! > > It has been a long battle with many late nights to g

Re: s/valid? vs. s/explain

2016-11-16 Thread James Gatannah
Thank you, Alex. Both for the feedback about what I'm doing wrong and for a fix that looks simple and obvious. Regards, James On Sunday, November 13, 2016 at 9:57:55 AM UTC-6, James Gatannah wrote: > > One of my system boundary data structures is particularly ugly. It > involves things like J