From: Damien Mattei <damien.mattei@gmail.com>
To: guile-user@gnu.org
Subject: Re: list vs vector
Date: Wed, 28 Dec 2022 19:29:31 +0100 [thread overview]
Message-ID: <CADEOaddsi=y-qchf175po9O4UZ73UxKTJ1SjV2JVNb40daeMOg@mail.gmail.com> (raw)
In-Reply-To: <CAGUt3y4ASWsVtVdduiRD99tZ1iDF97vvtmf3h_xi1UnyZcTNKQ@mail.gmail.com>
i have no idea, at the opposite, in one of my program i experienced a
vector implementation faster than the list one.
Regards,
Damien
On Wed, Dec 28, 2022 at 2:23 PM Sascha Ziemann <ceving@gmail.com> wrote:
> I spent my Christmas vacation playing with XML and tree traversal. And
> I have observed some strange timings, while measuring the execution
> time of different algorithms. My test file is the XCB XML schema:
>
> https://cgit.freedesktop.org/xcb/proto/plain/src/xcb.xsd
>
> And my test program is this:
>
> https://gist.github.com/ceving/6eb3792c64e505909f43858039ae18f8
>
> I load the XSD file with "(sxml simple)" and traverse the XML tree in
> order to remove all white-spaces. During the traversal of the tree I
> visit each element and destructure each element with the following
> procedure:
>
> (define (sxml:call-with-element node proc)
> (if (sxml:element? node)
> (let ((name (car node))
> (rest (cdr node)))
> (if (pair? rest)
> (let ((maybe-attributes (car rest)))
> (if (sxml:attributes? maybe-attributes)
> (proc name (cdr maybe-attributes) (cdr rest))
> (proc name '() rest)))
> (proc name '() '())))
> node))
>
> This is necessary, because in SXML the first child of an element may
> be an attribute list of an actual child element. After I had written
> the procedure, I had the impression that it might be faster to work
> with vectors instead of lists, because the version with vectors looks
> much simpler:
>
> (define (vxml:call-with-element node proc)
> (if (vxml:element? node)
> (proc (vxml:element-name node)
> (vxml:element-attributes node)
> (vxml:element-children node))
> node))
>
> But after I compared the two traversals, I had to realize that the
> list-version is a bit faster than the vector-version. Although the
> list-version does much testing, caring and cdring, the straight
> forward vector-ref's are slower. Can anybody explain?
>
>
next prev parent reply other threads:[~2022-12-28 18:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-28 13:22 list vs vector Sascha Ziemann
2022-12-28 14:34 ` tomas
2022-12-28 18:29 ` Damien Mattei [this message]
2022-12-28 20:23 ` Olivier Dion via General Guile related discussions
2022-12-29 9:43 ` Sascha Ziemann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CADEOaddsi=y-qchf175po9O4UZ73UxKTJ1SjV2JVNb40daeMOg@mail.gmail.com' \
--to=damien.mattei@gmail.com \
--cc=guile-user@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).