Guest User

pg_free_result() test

a guest
May 15th, 2013
713
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3. Example for: http://stackoverflow.com/questions/16554128
  4. "Is pg_free_result() necessary, even if the result goes out of scope?"
  5.  
  6. Output on PHP v5.3.10-1ubuntu3.6:
  7. ---------------------------------
  8. After 1000 runs with    pg_free_result():  160 bytes
  9. After 1000 runs without pg_free_result():  160 bytes
  10. */
  11.  
  12. const NUM_RUNS = 1000;
  13. $conn = pg_connect("dbname=xxx user=xxx");
  14. runTests(true);
  15. runTests(false);
  16.  
  17. function selectSomething ($free)
  18. {
  19.     $res = pg_query("SELECT * FROM example");
  20.     if ($free) {
  21.         pg_free_result($res);
  22.     }
  23. }
  24.  
  25. function runTests ($free)
  26. {
  27.     $before = memory_get_usage();
  28.     for ($i = 0; $i < NUM_RUNS; ++$i) {
  29.         selectSomething($free);
  30.     }
  31.     $after = memory_get_usage();
  32.     printf("After %d runs %-7s pg_free_result(): %4d bytes\n",
  33.         NUM_RUNS,
  34.         $free ? "with" : "without",
  35.         $after - $before);
  36. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×