Skip to content
Prev 309159 / 398506 Next

Parsing very large xml datafiles with SAX: How to profile <anonymous> functions?

Hi Frederic

 Perhaps the simplest way to profile the individual functions in your
handlers is to write the individual handlers as regular
named functions, i.e. assigned to a variable in your work space (or function body)
and then two write the handler functions as wrapper functions that call these
by name

  startElement = function(name, attr, ...) {
     # code you want to run when we encounter the start of an XML element
  }

  myText = function(...) {
     # code
  }

  Now, when calling xmlEventParse()

   xmlEventParse(filename,
                  handlers = list(.startElement = function(...) startElement(...),
                                  .text = function(...) myText(...)))

Then the profiler will see the calls to startElement and myText.

There is small overhead of the extra layers, but you will get the profile information.

  D.
On 10/26/12 9:49 AM, Frederic Fournier wrote: