unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* list vs vector
@ 2022-12-28 13:22 Sascha Ziemann
  2022-12-28 14:34 ` tomas
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Sascha Ziemann @ 2022-12-28 13:22 UTC (permalink / raw)
  To: guile-user

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?



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-12-29  9:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-28 13:22 list vs vector Sascha Ziemann
2022-12-28 14:34 ` tomas
2022-12-28 18:29 ` Damien Mattei
2022-12-28 20:23 ` Olivier Dion via General Guile related discussions
2022-12-29  9:43   ` Sascha Ziemann

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).