SHARE
TWEET

Untitled

a guest Aug 17th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. require_once(__DIR__ . '/config.php');
  4. raise_memory_limit(MEMORY_HUGE);
  5.  
  6. $method = 'get_records'; // One of the cases from the switch below.
  7. $numrows = 512 * 1024;
  8. $generatorquery = "
  9.         SELECT i AS id, 'A thirty-two char string' || lpad('' || i, 8) AS name
  10.           FROM generate_series(1, $numrows) i";
  11.  
  12. switch ($method) {
  13.     case 'none':
  14.         $data = [];
  15.         break;
  16.  
  17.     case 'array_fill_object':
  18.         $data = [];
  19.         for ($i = 0; $i < $numrows; $i++) {
  20.             $data[] = (object) ['id' => "$i", 'name' => 'A thirty-two char string' . str_pad($i, 8, STR_PAD_LEFT)];
  21.         }
  22.         break;
  23.  
  24.     case 'array_fill_object_other':
  25.         $data = [];
  26.         for ($i = 0; $i < $numrows; $i++) {
  27.             $row = new stdClass();
  28.             $row->id = "$i";
  29.             $row->name = sprintf('A thirty-two char string% 8d', $i);
  30.             $data[] = $row;
  31.         }
  32.         break;
  33.  
  34.     case 'get_records':
  35.         $data = $DB->get_records_sql($generatorquery);
  36.         break;
  37.  
  38.     case 'get_recordset':
  39.         $rs = $DB->get_recordset_sql($generatorquery);
  40.         $data = [];
  41.         foreach($rs as $row) {
  42.             $data[] = $row;
  43.         }
  44.         $rs->close();
  45.         break;
  46. }
  47.  
  48. //var_dump($data);
  49. $PAGE->set_context(context_system::instance());
  50. $PAGE->set_url('/dbmemtest.php');
  51. $PAGE->set_title('DB memory usage test');
  52.  
  53. echo $OUTPUT->header();
  54. echo $OUTPUT->heading($method);
  55. echo count($data);
  56.  
  57. echo $OUTPUT->footer();
  58.  
  59. // method              RAM (MB)      RAM peak (MB)
  60. // none                      39            40.2
  61. // array_fill_object        321           322.1
  62. // array_fill_object_other  449           450.1
  63. // get_records              369           554
  64. // get_recordset            352.8         354
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top