Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 359895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:26:13+00:00 2026-05-12T12:26:13+00:00

Many many times on a page I will have to set post and get

  • 0

Many many times on a page I will have to set post and get values in PHP like this

I just want to know if it is better to just continue doing it the way I have above or if performance would not be touched by adding it into a function like in the code below?

This would make it much easiar to write code but at the expense of making extra function calls on the page.

I have all the time in the world so making the code as fast as possible is more important to me then making it “easiar to write or faster to develop”

Appreciate any advice and please nothing about whichever makes it easier to develop, I am talking pure performance here =)

<?php
function arg_p($name, $default = null) {
    return (isset($_GET[$name]))?$_GET[$name]:$default;
}

$pagesize = arg_p('pagesize', 10);

$pagesize = (isset($_GET['pagesize'])) ? $_GET['pagesize'] : 10;

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T12:26:13+00:00Added an answer on May 12, 2026 at 12:26 pm

    If you have all the time in the world, why don’t you just test it?

    <?php
    // How many iterations?
    $iterations = 100000;
    
    // Inline
    $timer_start = microtime(TRUE);
    for($i = 0; $i < $iterations; $i++) {
      $pagesize = (isset($_GET['pagesize'])) ? $_GET['pagesize'] : 10;
    }
    $time_spent = microtime(TRUE) - $timer_start;
    printf("Inline: %.3fs\n", $time_spent);
    
    // By function call
    function arg_p($name, $default = null) {
      return (isset($_GET[$name])) ? $_GET[$name] : $default;
    }
    
    $timer_start = microtime(TRUE);
    for($i = 0; $i < $iterations; $i++) {
      $pagesize = arg_p('pagesize', 10);
    }
    $time_spent = microtime(TRUE) - $timer_start;
    printf("By function call: %.3fs\n", $time_spent);
    ?>
    

    On my machine, this gives pretty clear results in favor of inline execution by a factor of almost 10. But you need a lot of iterations to really notice it.

    (I would still use a function though, even if me answering this shows that I have time to waste 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Many times I get quick page design inputs from business/clients which will be finally
Many times I see statements like following Y.CustomApp.superclass.render.apply(this, arguments); I know how apply works.
I have one page with a Silverlight object on it, and many times when
Many times i run time consuming PHP scripts that echo status updates like 'batch
I have a database schema that stores one Page with many Revisions. Like a
I'm building a search page that will have many different search parameters that the
I have my webapplication structured like this: Main page with n links and a
I've got 2 fields to populate: how many times the page is called per
I have a asp.net page with .net controls. For a long time, many years,
Many times I needed a set of pointers. Every time that happens, I end

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.