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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:54:42+00:00 2026-05-26T21:54:42+00:00

i would like to know which one is the best for performance: 1- use

  • 0

i would like to know which one is the best for performance:

1- use smarty template ( or any other better)

<?php
$Smarty = new Smarty();
// set all the default variables and other config
$Smarty->assign('var1', 'hello');
$Smarty->assign('var2', 'world');
$Smarty->display('page.html');

2- use this code:

<?php
$var1 = 'hello';
$var2 = 'world';
echo "$var1 $var2";

3- use this code:

<?php
$var1 = 'hello';
$var2 = 'world';
echo $var1 . " " . $var2;

based on these 3 examples i cant think about a new one, which one is best to use when performance

note: of course i have more variables than this example.

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-26T21:54:42+00:00Added an answer on May 26, 2026 at 9:54 pm

    As far as I remember, concatenating PHP variables (as in your third example) is faster than using "$var1 $var2" given a mix of variables and constant strings as each token is evaluated on the fly (which is bad).

    So, between 2 and 3, I believe it depends on context: If you have a long string with a mix of variables and constants, then method 3 would be faster. Otherwise, if it’s identical to your example, 2 might be faster (however, the difference is negligible and therefore should be a moot point).

    Using a templating engine will always be slower than raw code.


    Now if you don’t have a very good reason to not use a templating engine, you should by all accounts use one. Why?

    • Separation of concerns: Your PHP shouldn’t care about your HTML and vice versa.
    • Maintenance: Maintaining can become a nightmare when you mix HTML and PHP (or any other language for that matter) and should really be avoided at all cost (unless you’re doing something blindingly trivial).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know which one is the best material that I can
I would like to know which one of the following is the best choice
I am creating an iphone performance app in which I would like to know
I would like to know Which is the best way to write Loops? Is
I would like to know which solution is the fastest and the best for
I would like to know which dependency described in my pom.xml brings a transitive
i would like to know , how ill know which inlines forms was edited?
I've got an executable file, and I would like to know which version(s) of
I would like to know the procedure which will give the out put about
I would like to know where can I find the code which eclipse uses

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.