Hi,
hier die Resultate:
Code:/*
// version 1
// 1. run 0.14501937151
// 2. run 0.145541801453
// 3. run 0.141622686386
// fastest run 0.0934751033783
while ($field = $meta->fetch_field()) {
$row[] = &$fields[$field->name];
}
call_user_func_array(array($stmt, 'bind_result'), $fields);
unset($meta, $row);
$i = 0;
while ($stmt->fetch()) {
foreach ($fields as $k => $v) {
$data[$i][$k] = $v;
}
$i++;
}
unset($stmt);
*/
/*
// version 2
// 1. run 0.163174314501
while ($field = $meta->fetch_field()) {
$row[] = &$fields[$field->name];
}
unset($meta);
call_user_func_array(array($stmt, 'bind_result'), $fields);
while ($stmt->fetch()) {
foreach ($fields as $k => $v) {
$c[$k] = $v;
}
$data[] = $c;
}
unset($stmt);
*/
/*
// version 3
// 1. run 0.164394264222
$bind_result = '$stmt->bind_result(';
while ($field = $meta->fetch_field()) {
$bind_result .= '$fields["'.$field->name.'"],';
}
unset($meta);
eval(rtrim($bind_result, ',') . ');');
while ($stmt->fetch()) {
foreach ($fields as $k => $v) {
$row[$k] = $v;
}
$data[] = $row;
}
unset($stmt);
*/
/*
// version 4
// 1. run 0.202926313878
while ($field = $meta->fetch_field()) {
$row[] = &$fields[$field->name];
}
unset($meta);
call_user_func_array(array($stmt, 'bind_result'), $fields);
$copy = create_function('$a', 'return $a;');
while ($stmt->fetch()) {
$data[] = array_map($copy, $fields);
}
unset($stmt);
*/
/*
// version 5
// 1. run 0.147740311622
// 2. run 0.144599089624
$bind_result = '$stmt->bind_result(';
while ($field = $meta->fetch_field()) {
$bind_result .= '$fields["'.$field->name.'"],';
}
unset($meta);
eval(rtrim($bind_result, ',') . ');');
$i = 0;
while ($stmt->fetch()) {
foreach ($fields as $k => $v) {
$data[$i][$k] = $v;
}
$i++;
}
unset($stmt);
*/
/*
// version 6
// 1. run 0.199761638641
while ($field = $meta->fetch_field()) {
$row[] = &$fields[$field->name];
}
unset($meta);
call_user_func_array(array($stmt, 'bind_result'), $fields);
while ($stmt->fetch()) {
$data[] = array_map($copy, $fields);
}
unset($stmt);
*/
/*
// version 7
// 1. run 0.145406525135
// 2. run 0.147244937418
// 3. run 0.146580169201
// 4. run 0.140648040772 (rtrim removed)
// 5. run 0.138385720253 ($i used as string and counter)
// 6. run 0.142242712975 ($i used as string and counter)
// fastest run 0.0888710021973
$i = '';
while ($field = $meta->fetch_field()) {
$i .= ($i ? ',' : '$stmt->bind_result(') . '$fields["' . $field->name . '"]';
}
unset($meta);
eval($i . ');');
$i = 0;
while ($stmt->fetch()) {
foreach ($fields as $k => $v) {
$data[$i][$k] = $v;
}
$i++;
}
unset($stmt);
*/
Tatsächlich kann man sich aussuchen, ob man nun Version 1 oder 7 nimmt. Von der Geschwindigkeit her macht das keinen Unterschied.
Ein Run beinhaltet übrigens den Schnitt aus 100 Durchläufen. In einem Durchlauf wurde das jeweilige Script 50x ausgeführt. Die Konnektierung zur Datenbank fand nur einmal pro Durchlauf statt (um einen realen Einsatz nachahmen zu können).
Gruß