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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:44:43+00:00 2026-05-29T09:44:43+00:00

Has anyone done a proper benchmark on the difference in performance between these three

  • 0

Has anyone done a proper benchmark on the difference in performance between these three foo functions?

function foo_global() {
}

class SomeClass {
  public function foo_dynamic() {
  }

  public static function foo_static() {
  }
}

To what I know global is fastest and dynamic slowest but I’d appreciate some more learned results.

Thanks

  • 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-29T09:44:43+00:00Added an answer on May 29, 2026 at 9:44 am

    In my tests the is virtually no difference:

    Function call benchmark

    So static calls are slightly slower than dynamic, and dynamic is slightly slower than global functions.

    <?php
    function pre_defined($v1, $v2) {
        return $v1 + $v2;
    }
    $anonymous = function($v1, $v2) {
        return $v1 + $v2;
    };
    $create_function = create_function('$v1, $v2', 'return $v1 + $v2;');
    
    class StaticFunction {
        public static function test($v1, $v2) {
            return $v1 + $v2;
        }
    }
    
    class DynamicFunction {
        public function test($v1, $v2) {
            return $v1 + $v2;
        }
    }
    $dynamic = new DynamicFunction();
    
    $v1 = 1;
    $v2 = 2;
    $iterations = 1000;
    Performance\BenchmarkManager::add_group('Function call', new Performance\BenchmarkGroup(array(
        'benchmarks' => array(
            'empty loop' => function() use($iterations, $v1, $v2) {
                for ($i = 0; $i < $iterations; $i++) {
                }
            },
            'native reference point' => function() use($iterations, $v1, $v2) {
                for ($i = 0; $i < $iterations; $i++) {
                    $result = $v1 + $v2;
                }
            },
            'pre defined' => function() use($iterations, $v1, $v2) {
                for ($i = 0; $i < $iterations; $i++) {
                    $result = pre_defined($v1, $v2);
                }
            },
            'anonymous' => function() use($iterations, $v1, $v2, $anonymous) {
                for ($i = 0; $i < $iterations; $i++) {
                    $anonymous($v1, $v2);
                }
            },
            'create_function' => function() use($iterations, $v1, $v2, $create_function) {
                for ($i = 0; $i < $iterations; $i++) {
                    $create_function($v1, $v2);
                }
            },
            'eval' => function() use($iterations, $v1, $v2) {
                for ($i = 0; $i < $iterations; $i++) {
                    eval('$result = $v1 + $v2;');
                }
            },
            'static' => function() use($iterations, $v1, $v2) {
                for ($i = 0; $i < $iterations; $i++) {
                    StaticFunction::test($v1, $v2);
                }
            },
            'dynamic' => function() use($iterations, $v1, $v2, $dynamic) {
                for ($i = 0; $i < $iterations; $i++) {
                    $dynamic->test($v1, $v2);
                }
            },
        ),
    )));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am curious if anyone has done a comparison between the different options out
Has anyone done this / have some example code?
Has anyone ever done work to get Ruby to do continuations (like Seaside on
Has anyone seen this before - and can anything be done about it? This
I want to trial Windows 7 but wondered if anyone who has done so
Has anyone done this? I would like to show a ! instead of a
Has anyone done this or attempted to do this for a preexisting project? It
Has anyone done any investigation as to whether the Apple AppStore distribution private key/certificate
Has anyone done this successfully? As I understand, GDI+ 1.1 only ships with Vista.
Has anyone done any Unity project where USB communication is done? I have to

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.