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
Merged

Conversation

dreamsxin
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor

Sweet!

@dreamsxin dreamsxin merged commit c339713 into zephir-lang:development Jun 30, 2019
@niden
Copy link
Contributor

niden 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
Copy link
Contributor Author

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

@niden
Copy link
Contributor

niden 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.

dreamsxin added a commit to dreamsxin/zephir that referenced this pull request Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants