That indeed provided a huge speed-up (0.5s compared to 1.5 originally).
Cheers Timothy
On Sunday, 1 December 2013 02:19:44 UTC+10:30, tbc++ wrote:
>
> There's several ways the performance of this code can be improved.
>
> Firstly, these are exactly the same (samantically), but the latter is much
> faster: (go (>! c v)) and (put! c v). Use put! whenever possible.
>
> Secondly, the function "event" uses <!! (blocking take), but it's used
> inside a go later on. Don't do this, it can cause issues in the go's fixed
> thread pool.
>
> I think you can also improve this code quite a bit by reducing the number
> of puts/takes the system is doing. So consider changing this:
>
> (defn event [env type val]
> (let [rc (async/chan)]
> (async/<!!
> (async/go
> (async/>! (:queue @env)
> {:type type :val val :rc rc :time (:now @env)})
> (async/<! rc)
> (async/close! rc)))))
>
> (event ....)
>
> To this:
>
>
> (defn event [env type val]
> (let [rc (async/chan)]
> (*put!*
>
> (:queue @env)
>
> {:type type :val val :rc rc :time (:now @env)}))
> rc))
>
> (<! (event ...))
>
> I have not benchmarked this new code, but it should run much faster.
> Timothy
>
>
>
> On Fri, Nov 29, 2013 at 5:04 PM, kandre <[email protected]<javascript:>
> > wrote:
>
>> Here is the gist: https://gist.github.com/anonymous/7713596
>> Please not that there's no ordering of time for this simple example and
>> there's only one event (timeout). This is not what I intend to use but it
>> shows the problem.
>> Simulating 10^5 steps this way takes ~1.5s
>>
>> Cheers
>> Andreas
>>
>> On Saturday, 30 November 2013 09:31:08 UTC+10:30, kandre wrote:
>>>
>>> I think I can provide you with a little code snipped.
>>> I am talking about the very basic car example
>>> (driving->parking->driving). Running the sim using core.async takes about
>>> 1s for 10^5 steps whereas the simpy version takes less than 1s for 10^6
>>> iterations on my vm.
>>> Cheers
>>> Andreas
>>>
>>> On Saturday, 30 November 2013 09:22:22 UTC+10:30, Ben Mabey wrote:
>>>>
>>>> On Fri Nov 29 14:13:16 2013, kandre wrote:
>>>> > Thanks for all the replies. I accidentally left out the close! When I
>>>> contrived the example. I am using core.async for a discrete event
>>>> simulation system. There are hundreds of go blocks all doing little but
>>>> putting a sequence of events onto
>>>
>>>
>>
>>> a channel and one go block advancing taking these events and advancing
>>>> the time similar to simpy.readthedocs.org/
>>>> >
>>>> > The basic one car example under the previous link executes about 10
>>>> times faster than the same example using core.a sync.
>>>> >
>>>>
>>>> Hi Andreas,
>>>> I've been using core.async for DES as well since I think the
>>>> process-based approach is useful. I could try doing the same
>>>> simulation you're attempting to see how my approach compares
>>>> speed-wise. Are you talking about the car wash or the gas station
>>>> simulation? Posting a gist of what you have will be helpful so I can
>>>> use the same parameters.
>>>>
>>>> -Ben
>>>>
>>>>
>>>>
>>>>
>>>> --
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to [email protected]<javascript:>
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> [email protected] <javascript:>
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>
>
> --
> “One of the main causes of the fall of the Roman Empire was that–lacking
> zero–they had no way to indicate successful termination of their C
> programs.”
> (Robert Firth)
>
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.