#!/usr/bin/env entity

<object>
  
  <timer interval="2000" action="search"/>
  <?perl
    
    sub showtime
    {
        $TIMEVAL_T = "LL";
	my $thetime = pack($TIMEVAL_T, ());
	syscall (&SYS_gettimeofday, $thetime, 0) != -1
		or die "gettimeofday: $!";
	
	my @ltime = unpack($TIMEVAL_T, $thetime);
	return ("$ltime[0]" . "." . "$ltime[1]");
    }
      
    require 'sys/syscall.ph';
  
    my $numnodes = 10000;
    
    my $start = showtime();
    print ("creating $numnodes node tree: ");
    
    my $obj = enode ("object");
    
    $obj->attrib ("foo" => "goo");
    
    for (my $i = 0; $i < $numnodes; $i++) {
        my $node = $obj->new_child ("fooey");
	$node->attrib ("foo" => "goo") 	if (! ($i % 2));
    }

    print (showtime() - $start, " s\n");
    
    sub search
    {
        my $st = showtime();
        print ("\nsearching $numnodes node tree: ");
	my @list = enode("object")->children_attrib ("foo", "goo");
	print (showtime() - $st . " s\n");
	my $num = @list;
	print ("returned $num results.\n");
#	foreach $node (@list) {
#	    print ("$node\n");
#	}
#	 
#	enode("object")->call ("entity:quit");
    }
    
    
  ?>

</object>
