Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Example for: http://stackoverflow.com/questions/16554128
- "Is pg_free_result() necessary, even if the result goes out of scope?"
- Output on PHP v5.3.10-1ubuntu3.6:
- ---------------------------------
- After 1000 runs with pg_free_result(): 160 bytes
- After 1000 runs without pg_free_result(): 160 bytes
- */
- const NUM_RUNS = 1000;
- $conn = pg_connect("dbname=xxx user=xxx");
- runTests(true);
- runTests(false);
- function selectSomething ($free)
- {
- $res = pg_query("SELECT * FROM example");
- if ($free) {
- pg_free_result($res);
- }
- }
- function runTests ($free)
- {
- $before = memory_get_usage();
- for ($i = 0; $i < NUM_RUNS; ++$i) {
- selectSomething($free);
- }
- $after = memory_get_usage();
- printf("After %d runs %-7s pg_free_result(): %4d bytes\n",
- NUM_RUNS,
- $free ? "with" : "without",
- $after - $before);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement