published over 3 years ago (27.03.2007 08:06)

PHP: a quick SimpleXML benchmark

update: needs work to become comparable with the ruby benchmark posted earlier.

as an update to the ruby xml performance test, some info for PHPs standard way of parsing XML, SimpleXML. since it uses libxml2 internally, the results are more comparable to ruby’s libxml2 parser, although not identical … (i don’t yet understand where the factor 10 difference in xpath comes from).

loading an xml file

file size ms
10KB 0.71
100KB 5.88
1.6MB 120.97

simple xpath expression

file size ms
10KB 0.75
100KB 6.39
1.6MB 79.52

the test code

<?php

function benchmark($function)
{
   $start = microtime(true);
   for ($i=0; $i<10; $i++) {
      // execute the anonymous function ("yield")
      $function();
   }
   echo ((microtime(true) - $start) / 10) * 1000;
   echo "\n";
} 

// put file into filesystem cache (hope this works)
file_get_contents('products.xml');
/**
 * info: using create_function does not change performance 
 * (in comparison with executing the code in a more traditional php way)
 */

// loading xml into an object
benchmark(
   create_function(
      // function arguments as string
      '',
      // method body as string
      '$doc = simplexml_load_file("products.xml");'
   )  
); 

benchmark(
   create_function(
      // function arguments as string
      '',
      // method body as string
      '$doc = simplexml_load_file("products.xml");
       foreach ($doc->xpath("//articles/article/shortdesc") as $node) {
          //echo $node;
       }'
   )
);

?>

Posted in ,  | Tags , , ,  | no comments

published over 3 years ago (27.03.2007 07:43)

extending PHP's SimpleXML

PHP’s XML workhorse, SimpleXML can be extended. you can supply a class of your own for PHP to wrap all XML nodes instead of the default SimpleXMLElement. do this by passing the desired class name as a string to the simplexml_load_(file|string) methods:

<?php

class MySimpleXMLElement extends SimpleXMLElement
{     
   // extending parent method
   public function xpath($path)
   {  
      echo "evaluating the following xpath expression: $path\n";
      $result = parent::xpath($path);
      echo "found " . sizeof($result) . " nodes";
      return $result;
   }
}

$doc = simplexml_load_file('products.xml', 'MySimpleXMLElement');
// calling an extended method
$nodes = $doc->xpath('//articles/article/shortdesc');
echo "\n";

// calling a parent method
echo $doc->root->getName();
echo "\n";

?>

i didn’t poke around in the internals of the parent class too much, no idea how well that would. on the other hand, in many cases it might be a better solution to delegate to SimpleXML instead of inheriting and extending from it.

Posted in ,  | Tags , ,  | no comments

published over 3 years ago (18.03.2007 11:20)

ruby: performance comparison of rexml and libxml

update: here’s the same for PHP’s XML Parser.

a quick comparison of the two libraries available for processing XML in ruby shows dramatic performance differences.

am i missing something, is there a fundamental flaw in the test? of course REXML is pure ruby, while libxml is C; but can the difference really be so huge?

loading an xml file

file size libxml REXML factor
10KB 0,83 39,17 47,0
100KB 6,67 306,56 46,0
1.6MB 71,88 3954,21 55,0

simple xpath expression

file size libxml REXML factor
10KB 0,12 124,68 1004,7
100KB 0,67 678,11 1016,8
1.6MB 6,21 22578,18 3633,6

the test code

def benchmark
   start = Time.new.to_f
   10.times { yield }
   puts ((Time.new.to_f - start) / 10) * 1000
end

doc = nil

# exclude the effect of filesystem caching (makes sense?)
File.read('products.xml')

#
# libxml
#
require 'rubygems'
require 'xml/libxml'

benchmark do
   doc = XML::Document.file("products.xml")
end

benchmark do
   doc.find('//articles/article/shortdesc').each do |node|
      #puts node.content
   end
end

#
# rexml
#
require "rexml/document"

benchmark do
   doc = REXML::Document.new File.read("products.xml")
end

benchmark do
   doc.elements.each("//articles/article/shortdesc") do |node| 
      #puts node.text
   end
end

Posted in , ,  | Tags , , , ,  | no comments

published over 3 years ago (17.03.2007 17:12)

Top Ten Things They Never Taught Me in Design School

well, not that i went to design school … but this is an insightful summary on how to achieve things, no matter whether they’re work or play.

  1. Talent is one-third of the success equation.
  2. 95 percent of any creative profession is shit work.
  3. If everything is equally important, then nothing is very important.
  4. Don’t over-think a problem.
  5. Start with what you know; then remove the unknowns.
  6. Don’t forget your goal.
  7. When you throw your weight around, you usually fall off balance.
  8. The road to hell is paved with good intentions; or, no good deed goes unpunished.
  9. It all comes down to output.
  10. The rest of the world counts.

read the full post at designobserver.com

Posted in ,  | no comments

published over 3 years ago (11.03.2007 23:44)

blödchen für paris!

on ifilm.

Posted in ,  | no comments

published over 3 years ago (11.03.2007 09:57)

Grossstadtgeflüster- Ich Muss Gar Nix

shouting »ich muss gar nix … ausser schlafen trinken atmen und ficken, und nach meinen selbstgeschriebenen regeln ticken« … to bouncing electronic bleeps.

music from berlin – of course :-)

Posted in , , ,  | no comments

published over 3 years ago (11.03.2007 00:03)

quote five

»Those who do not learn from history are doomed to repeat it.« — George Santayana

Posted in  | no comments

published over 3 years ago (10.03.2007 23:53)

2 more addictive games

stackopolis (online) and frenzic (download).

oh, and don’t forget poom (online)!

and fancy pants (online)!

Posted in  | no comments

published over 3 years ago (10.03.2007 20:27)

Does Marcellus Wallace look like a bitch?

wonderful typography, animated.

via stefan tilkov and steve's new company's blog.

Tags ,  | no comments

published over 3 years ago (03.03.2007 12:43)

shutdownday.org

  • can you survive a day without a computer?
  • what would you do that day?
  • would you get mor or less done?
  • would you have to plan ahead, or settle some things beforehand?
  • would you be more in contact with your friends, family and self?
  • would you get more or less stuff done, and of what kind of stuff?
  • what would today be different if there were no computers?

hint: the 24th is a saturday …

and here are some ideas how you can have fun with your computer on that day, without turning it on!

Posted in  | no comments