Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion doall, dorun, doseq, for
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Chouser  
View profile  
 More options Mar 3 2009, 9:30 pm
From: Chouser <chou...@gmail.com>
Date: Tue, 3 Mar 2009 21:30:15 -0500
Local: Tues, Mar 3 2009 9:30 pm
Subject: Re: doall, dorun, doseq, for

On Tue, Mar 3, 2009 at 2:54 PM, Mark Volkmann <r.mark.volkm...@gmail.com> wrote:

> I agree that using doseq instead of dorun results in code that is
> easier to read. I don't understand though why it is more efficient.
> They both walk the entire sequence, neither holds onto the head and
> both return nil. Why is doseq more efficient than dorun?

A simple doseq does run about as fast as dorun on the same seq.  Bus
something like this would be more likely (let's pretend inc has useful
side-effects):

  (defn f [] (dorun (map #(inc %) (range 10000000))))

  (defn f2 [] (doseq [i (range 10000000)] (inc i)))

The results would be the same, but dorun requires 'map', which creates
another seq.  'doseq' is able to accomplish the same work with less
allocation.

  user=> (time (f))
  "Elapsed time: 1685.796066 msecs"

  user=> (time (f2))
  "Elapsed time: 531.730209 msecs"

--Chouser


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.