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 9268793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:56:58+00:00 2026-06-18T14:56:58+00:00

I was writing some simple file manipulation and a thought came up if it

  • 0

I was writing some simple file manipulation and a thought came up if it wouldn’t be faster if I saved the string size in variable. It showed up that it is 10 times faster.
Using this code:

include "../classes/Timer.class.php";
$t = new Timer();             //Timer class I've written for this purpose [link below]
$multiplyer = 3000000;        //Times to try the operation
$string = str_repeat("ggggggggggg",2);  //I first tried 2000 here, but for 2 there are same results
$t("calling");     //Saving time
for($i=0; $i<$multiplyer; $i++) {
  $size =  strlen($string);
  $size2 = strlen($string);
  $size3 = strlen($string);
}
$t("clover");
$t("caching");     //Saving time
for($i=0; $i<$multiplyer; $i++) {
  $size =  strlen($string);
  $size2 = $size;
  $size3 = $size;
}
$t("chover");
$total = $t["calling-clover"]+$t["caching-chover"];  //percents are usefull :)
echo "Calling: {$t["calling-clover"]} (".round(($t["calling-clover"]/$total)*100)."%)<br>\n";
echo "Caching in variables: {$t["caching-chover"]} (".round(($t["caching-chover"]/$total)*100)."%)<br>\n";

Results:

Calling: 1.988455057 (67%)
Caching in variables: 0.984993458 (33%)

What is even more interesting is the fact, that it does not matter what number I put in the str_repeat call, so the strlen obviously does not compute anything – the size must be saved somewhere and strlen is just function that returns value.
This implies:
Are really function calls so slow?
If not, is this strlen specific?


Timer.class.php

  • 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-06-18T14:57:00+00:00Added an answer on June 18, 2026 at 2:57 pm

    There is much more to a function call than a variable retrieval. Every time you execute a function:

    1. A new stack is created and arguments to the function are stored on the stack.
    2. Memory is allocated on the stack for the return value of the function
    3. The previously allocated memory address is stored on the stack
    4. The address of the function is called
    5. The function reads the arguments from the stack
    6. Return value is stored in the stack
    7. Execution is restored to the caller and the stack is cleared
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a bit confused. I'm writing a very simple file system that basically: -reads
I have some problems in writing down the schema of my XML file, that
I'm writing code that will, when a button is clicked, display some simple text
I am writing a simple Groovy application that needs to do some logging. The
I am writing some simple code to parse a file and return the number
So I'm writing what I thought was a simple .rb file to convert a
I'm writing a chrome extension that do some simple stuff. now, I made a
I'm writing a simple .bat file and I've run into some weird behavior. There
I'm writing some simple DAOs in Java using JDBC (no Spring, Hibernate or anything
I'm writing some code which could really do with some simple compile time metaprogramming.

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.