How fast will this load?
hi, i'm a noob at php, and want to know if the code i made will significantly increase the page loading time. if yes, would it be smart to use my code to generate html and then save it as static html?
i've got an array of arrays structure as following:
and there are around a hundred of arrays (inside the $item array) and each of those arrays gets its elements (a-k) checked twice, like this:
$item = array (
"a" => "",
"b" => "",
"c" => "",
"d" => "",
"e" => "",
"f" => "",
"g" => "",
"h" => "",
"i" => "",
"j" => "",
"k" => ""
if($item[$i]["a"]) $title.=$item[$i]["a"] . ", ";
if($item[$i]["b"]) $title.=$item[$i]["b"] . ", ";
$i is from - for($i=0; array_key_exists($i, $item); $i++)
if($item[$i]["a"]) echo("<p>" . $item[$i]["a"] . "</p>");
if($item[$i]["b"]) echo("<p>" . $item[$i]["b"] . "</p>");
so, will it be too slow? thanks a lot
No clue with respect to your question, but if you wish to speed up execution of this code, then there are some steps you can take.
First, don't loop through every "a", "b", "c", etc. manually, that's a waste of code. You can simply use a single for loop and convert necessary integers to their ASCII counterparts. Since each character is represented by an ASCII value, we can easily work this out.
This is one of the first things I learnt in C and C++, so it's pretty easy in PHP.
Take note here that the integer values for a-z are 97-122. For A-Z, you need to begin at 65. Here's some sample code:
Secondly, your code has an error. You've not added on the last bracket for your array or terminated the statement.
for($i = 0; $i < 26; $i++)
echo chr($i + 97);
echo "<br />";
for($i = 0; $i < 26; $i++)
echo chr($i + 65);
Not quite sure what you're trying to achieve here? Post a detailed response and maybe someone will be able to help you out more.
thanks for your response george, but the code i put is a simplified version of the one i have, here is something more like it
there is no problem with the code, i was just wondering whether this many loops would slow the loading speed and if copying the html generated with php and then saving it as html makes any sense (thereby using php just as somewhat of an editor to create static pages).
$item array (
//10 more variables
//100 more arrays
for($i=0; array_key_exists($i, $item); $i++)
if($item[$i]["height"]) echo("<p>" . $item[$i]["height"] . " centimeters</p>");
if($item[$i]["weight"]) echo("<p>" . $item[$i]["weight"] . " kilograms</p>");
if($item[$i]["note"]) echo("<p>note this: " . $item[$i]["note"] . "</p>");
//10 more echos, and the same number of similar lines such as this one:
if($item[$i]["height"]) $title.=$item[$i]["height"] . " centimeters, ";
Last edited by janje; 07-13-2012 at 02:13 PM.
I'm sorry, but I'm a little confused about what you're asking for. I don't know what on earth your code is doing so I can't advise you based on that.
The only advice I can offer you is that if you notice a slowing down of your loading time, then you should consider why and if it will affect your users experience.
You can test for load times using Firebug or the built-in console window in Google Chrome, but it won't tell you how fast or slow the code executes. I wouldn't think 100 loops is a significant enough number to make a difference to performance on todays web server standards, anyway. If Facebook can find a username and password in a database, or set of databases, with billions of people inside, I'm sure your code will work just fine and no one is going to notice a thing.
thank you, that is what i wanted to hear.
my apologies for not clearing out what i'm doing here, i thought it wont be necessary. anyhow, i've got a website for let's say furniture (each of those arrays represents a piece of furniture), and it is all in html, so maintaining the site became a pain in the ass cause i have to write down html for every single new item (and everything has to be written down twice, in different structures), and i decided to make things easier for myself so i created this small code that builds the entire website just as it was from the info i put in those arrays, which are pretty simple and clear to maintain. then i got to the question if all those loops will make things any slower (there are like 20 checks if the variable is empty (or exists?) inside each of the 100 arrays), and then i realised i could actually copy the html that was generated and be slower on updating for one copypaste than using the mentioned php code.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)