<commit_before><?php

set_include_path(dirname(__FILE__) . '/../../../../');
define('LIMB_VAR_DIR', dirname(__FILE__) . '/../../../var/');

$mark = microtime(true);

require_once('limb/core/common.inc.php');
require_once('limb/active_record/common.inc.php');

echo "active record common includes: " . (microtime(true) - $mark) . "\n";

$db = LIMB_VAR_DIR . '/benchdb';
if($native_db = sqlite_open($db))
{
  @sqlite_query($native_db, "DROP TABLE foo");
  sqlite_query($native_db, 'CREATE TABLE foo (id INTEGER PRIMARY KEY, bar VARCHAR(10))');
  for($i=0;$i<30;$i++)
    sqlite_query($native_db, "INSERT INTO foo VALUES (null, 'some value$i')");
}
else
  throw new Exception("Could not open sqlite db '$db'");

$mark = microtime(true);

for($i=0;$i<1000;$i++)
{
  $query = sqlite_query($native_db, 'SELECT bar FROM foo');
  while($entry = sqlite_fetch_array($query, SQLITE_ASSOC))
   $bar = $entry['bar'];
}

echo "native sqlite fetching: " . (microtime(true) - $mark) . "\n";

$conn = lmbDBAL :: newConnection('sqlite://localhost/' . $db);
$mark = microtime(true);

for($i=0;$i<1000;$i++)
{
  $rs = lmbDBAL :: fetch('SELECT bar FROM foo', $conn);
  foreach($rs as $record)
   $bar = $record->get('bar');
}

echo "lmbDBAL :: fetch(), getter: " . (microtime(true) - $mark) . "\n";

class Foo extends lmbActiveRecord{}

lmbActiveRecord :: setDefaultDSN('sqlite://localhost/' . $db); 

$mark = microtime(true);

for($i=0;$i<1000;$i++)
{
  $rs = lmbActiveRecord :: find('Foo');
  foreach($rs as $obj)
    $foo = $obj->get('bar');
}

echo "lmbActiveRecord fetching, getter: " . (microtime(true) - $mark) . "\n";

$mark = microtime(true);

for($i=0;$i<1000;$i++)
{
  $rs = lmbActiveRecord :: find('Foo');
  foreach($rs as $obj)
    $foo = $obj->bar;
}

echo "lmbActiveRecord fetching, attr access: " . (microtime(true) - $mark) . "\n";

$mark = microtime(true);

for($i=0;$i<1000;$i++)
{
  $rs = Foo :: find();
  foreach($rs as $obj)
    $foo = $obj->get('bar');
}

echo "Foo fetching, getter: " . (microtime(true) - $mark) . "\n";

@unlink($db);
<commit_msg>[svn r6907] -- adding more tests into bench<commit_after><?php

set_include_path(dirname(__FILE__) . '/../../../../');
define('LIMB_VAR_DIR', dirname(__FILE__) . '/../../../var/');

$mark = microtime(true);

require_once('limb/core/common.inc.php');
require_once('limb/active_record/common.inc.php');

echo "active record common includes: " . (microtime(true) - $mark) . "\n";

$db = LIMB_VAR_DIR . '/benchdb';
if($native_db = sqlite_open($db))
{
  @sqlite_query($native_db, "DROP TABLE foo");
  sqlite_query($native_db, 'CREATE TABLE foo (id INTEGER PRIMARY KEY, bar VARCHAR(10))');
  for($i=0;$i<30;$i++)
    sqlite_query($native_db, "INSERT INTO foo VALUES (null, 'some value$i')");
}
else
  throw new Exception("Could not open sqlite db '$db'");

$mark = microtime(true);

for($i=0;$i<1000;$i++)
{
  $query = sqlite_query($native_db, 'SELECT bar FROM foo');
  while($entry = sqlite_fetch_array($query, SQLITE_ASSOC))
   $bar = $entry['bar'];
}

echo "native sqlite fetching: " . (microtime(true) - $mark) . "\n";

$conn = lmbDBAL :: newConnection('sqlite://localhost/' . $db);

$mark = microtime(true);

for($i=0;$i<1000;$i++)
{
  $rs = lmbDBAL :: fetch('SELECT bar FROM foo', $conn);
  foreach($rs as $record)
   $bar = $record->get('bar');
}

echo "lmbDBAL :: fetch(), getter: " . (microtime(true) - $mark) . "\n";

$mark = microtime(true);

$rs = lmbDBAL :: fetch('SELECT bar FROM foo', $conn);
for($i=0;$i<1000;$i++)
{
  foreach($rs as $record)
   $bar = $record->get('bar');
}

echo "lmbDBAL :: fetch()(out of loop), getter: " . (microtime(true) - $mark) . "\n";

class Foo extends lmbActiveRecord{}

lmbActiveRecord :: setDefaultDSN('sqlite://localhost/' . $db); 

$mark = microtime(true);

for($i=0;$i<1000;$i++)
{
  $rs = lmbActiveRecord :: find('Foo');
  foreach($rs as $obj)
    $foo = $obj->get('bar');
}

echo "lmbActiveRecord fetching, getter: " . (microtime(true) - $mark) . "\n";

$mark = microtime(true);

$rs = lmbActiveRecord :: find('Foo');
for($i=0;$i<1000;$i++)
{
  foreach($rs as $obj)
    $foo = $obj->get('bar');
}

echo "lmbActiveRecord fetching(out of loop), getter: " . (microtime(true) - $mark) . "\n";

$mark = microtime(true);

for($i=0;$i<1000;$i++)
{
  $rs = lmbActiveRecord :: find('Foo');
  foreach($rs as $obj)
    $foo = $obj->bar;
}

echo "lmbActiveRecord fetching, attr access: " . (microtime(true) - $mark) . "\n";

$mark = microtime(true);

$rs = lmbActiveRecord :: find('Foo');
for($i=0;$i<1000;$i++)
{
  foreach($rs as $obj)
    $foo = $obj->bar;
}

echo "lmbActiveRecord fetching(out of loop), attr access: " . (microtime(true) - $mark) . "\n";

$mark = microtime(true);

for($i=0;$i<1000;$i++)
{
  $rs = Foo :: find();
  foreach($rs as $obj)
    $foo = $obj->get('bar');
}

echo "Foo fetching, getter: " . (microtime(true) - $mark) . "\n";

@unlink($db);

{'fraction_non_alphanumeric': 0.23341573959620932, 'fraction_numerical': 0.016275236918005767, 'mean_word_length': 4.358719646799117, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1778228', 'n_tokens_mistral': 2007, 'n_tokens_neox': 1907, 'n_words': 399}