Changeset 42 for trunk/ext/php/syck.php

Show
Ignore:
Timestamp:
03/19/2003 19:06:55 (6 years ago)
Author:
whythluckystiff
Message:

Updates to the PHP, Python extensions.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/ext/php/syck.php

    r23 r42  
    1010} 
    1111echo "<br>\n"; 
    12 echo "Testing load: "; 
    13 print_r( syck_load( "{test: &anc {and: 2}, or: {alias: *anc}}" ) ); 
     12echo "Testing load: \n"; 
     13$doc =<<<YAML 
     14-  
     15  a: 1 
     16  b: 2 
     17  c: 3 
     18  d: TRUE 
     19  e: ~ 
     20  f: test_me 
     21  g: 
     22    test: also 
     23  h: 0xFF 
     24  i: 012 
     25YAML; 
     26 
     27$iter = 10000; 
     28 
     29echo "DOC #1 = $iter x " . strlen( $doc ) . "\n"; 
     30$syck_start = microtime(); 
     31foreach( range( 0, $iter ) as $i ) 
     32{ 
     33    $test_obj = syck_load( $doc ); 
     34} 
     35$syck_stop = microtime(); 
     36 
     37$test_str = serialize( $test_obj ); 
     38$unser_start = microtime(); 
     39foreach( range( 0, $iter ) as $i ) 
     40{ 
     41    $test_obj = unserialize( $test_str ); 
     42} 
     43$unser_stop = microtime(); 
     44 
     45$doc2 = ""; 
     46foreach( range( 0, $iter ) as $i ) 
     47{ 
     48    $doc2 .= $doc . "\n"; 
     49} 
     50echo "DOC #2 = 1 x " . strlen( $doc2 ) . "\n"; 
     51$syck2_start = microtime(); 
     52$test_obj = syck_load( $doc2 ); 
     53$syck2_stop = microtime(); 
     54 
     55$test_str = serialize( $test_obj ); 
     56$unser2_start = microtime(); 
     57$test_obj = unserialize( $test_str ); 
     58$unser2_stop = microtime(); 
     59 
     60 
     61function elapsed( $start, $stop ) 
     62{ 
     63    $start_mt = explode( " ", $start ); 
     64    $stop_mt = explode( " ", $stop ); 
     65    $start_total = doubleval( $start_mt[0] ) + $start_mt[1]; 
     66    $stop_total = doubleval( $stop_mt[0] ) + $stop_mt[1]; 
     67    return sprintf( "%0.6f", $stop_total - $start_total ); 
     68} 
     69 
     70echo "syck:  " . elapsed( $syck_start, $syck_stop ) . " " . elapsed( $syck2_start, $syck2_stop ) . "\n"; 
     71echo "php:   " . elapsed( $unser_start, $unser_stop ) . " " . elapsed( $unser2_start, $unser2_stop ) . "\n"; 
     72 
    1473?>