Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with script speed improvement

Status
Not open for further replies.

georgeocrawford

Technical User
Aug 12, 2002
111
GB
Hi,

I would like some advice on improving the speed of my current php script.

It is a script I have written which displays encoded music data on screen like normal printed music.

The script works very well, just a bit slow. Basically it has two main steps:

1) Analyses encoded data, chopping it up into chords and measures. Then adds each note into a huge multi-dimensional array, composed of arrays for each system number, bar number, chord number, etc.

2) Cycles through each chord in the array, printing the relavent characters of my music font with
Code:
ImageTTFText
to a png image at the correct coordinates.


I am testing this at present with pieces about 300 bars long. Stage 1, which creates the 'master array', takes about 0.5 seconds. However, stage 2, which prints characters on the png image, takes about 10 seconds for 300 bars.

My question: Would this be quicker:

1) as above
2) cycle through 'master array' and calculate the coordinates for each chord. Create a 2nd array with 3 entries for each chord: 'x coordinate', 'y coordinate' and 'symbol to be printed'.
3) cycle through this array and use a
Code:
foreach
loop in conjunction with the
Code:
ImageTTFText
function to print to the image.

(sorry if this is confusing!)

I'm guessing it's the actual
Code:
ImageTTFText
function which slows the whole process down. With that in mind, would this part of my script run faster if it has a very easy array to loop through?


If you can't answer my question, could you perhaps suggest a site I can look at with advice for speeding up php scripts - i.e. which functions to avoid, or when and where not to use loops, arrays, etc.

Thanks for your help.
 
Chances are that the png generation is taking the time, when you create the image is it one mage or lots of small ones? I would suggest tring to map one large image as it *should* be quicker to process.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
No - I only create one image. For my example of 300 bars, the image produced is 850 x 3430 pixels - i.e. very large.

However, if I halt the script just before the png file is created and written to, the whole process is shortened by only about 0.5 seconds.

No, it's definately the large number of calls to the
Code:
ImageTTFText
function which are slowing the script.

Thanks for your help. Any more suggestions? ______________________

George
 
More suggestions:

1) do it the other way and write a lot if small images.

2) create each image possible andthen just call them when required? - an awful lot of work initially but would be much quicker later.
______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Hmm....

2) is a no-no!

1) needs experimenting with. I'll give it a go!

Thanks ______________________

George
 
on the note of 2, something I did for a slow running image gallery:

create each image and save to file, then only create images that weren't on file.

if(!file(imagename.png)){
//create image
//use image
//save image
}

This way you *should* end up with every possible combination , only creating images that don't exist already, this would be a progressively faster result. ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top