Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizing memory #1882

Merged
merged 1 commit into from Jun 30, 2019

Conversation

@dreamsxin
Copy link
Member

commented Jun 30, 2019

Hello!

  • Type: code quality
  • Link to issue:

In raising this pull request, I confirm the following:

  • I have checked that another pull request for this purpose does not exist
  • I wrote some tests for this PR
  • I updated the CHANGELOG

Small description of change:

Thanks

@dreamsxin

This comment has been minimized.

Copy link
Member Author

commented Jun 30, 2019

After
Zephir code:

namespace Mytest;

class App
{
	public function fibonacci(int  n) -> int {
		if (n == 1 ||  n == 0){
			return n;
		}

		return  this->fibonacci(n - 1) + this->fibonacci(n - 2);
	}

	internal function _fibonacci(long n) {
		if (n == 1 ||  n == 0){
			return n;
		}

		return  this->_fibonacci(n - 1) + this->_fibonacci(n - 2);
	}

	public function fibonacci2(int n){
		this->_fibonacci(n);
	}
}

Test code

function getMillisecond() {
    list($t1, $t2) = explode(' ', microtime());
    return (float)sprintf('%.0f',(floatval($t1)+floatval($t2))*1000);
}

class Test {
	function fibonacci($n)
	{
		if ($n == 1 or $n == 0) {
			return $n;
		}
		return $this->fibonacci($n - 1) + $this->fibonacci($n - 2);
	}
}
$test = new Test;
$startTime = getMillisecond();
$v = $test->fibonacci(30);
$endTime = getMillisecond();
echo 'PHP      '.($endTime - $startTime).PHP_EOL;

$app = new \Mytest\App;
$startTime = getMillisecond();
$app->fibonacci(30);
$endTime = getMillisecond();
echo 'Zephir   '.($endTime - $startTime).PHP_EOL;

$startTime = getMillisecond();
$app->fibonacci2(30);
$endTime = getMillisecond();
echo 'internal '.($endTime - $startTime).PHP_EOL;

Before optimization

PHP      320
Zephir   1333
internal 880

After optimization

PHP      324
Zephir   803
internal 400
@ruudboon

This comment has been minimized.

Copy link
Member

commented Jun 30, 2019

Sweet!

@dreamsxin dreamsxin merged commit c339713 into phalcon:development Jun 30, 2019
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@niden

This comment has been minimized.

Copy link
Member

commented Jun 30, 2019

@dreamsxin If you have not already, can you check internal in Windows build? I remember the last time I used internal the Windows build (appveyor) was failing.

@dreamsxin

This comment has been minimized.

Copy link
Member Author

commented Jun 30, 2019

@niden What error, It's show AppVeyor build succeeded.

@niden

This comment has been minimized.

Copy link
Member

commented Jun 30, 2019

@dreamsxin This was a few months ago when I used internal I do not have the build URL unfortunately. I will however try the internal again and will let you know.

Thanks bud.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.