about typecasting and script optimization

Started on the old forum in August 2012 · view the original in the archive · old links redirect here

5 replies · 533 views · started 14 years ago · 1 min read

2 participants
mFreak Developer · 66 posts #1

while reading scripts i downloaded here, i noticed that most of the users use *val() (intval,strval,...) funtions to typecast a variable. Well I just wanted to tell them that calling functions in php can slow down your script execution, especially when you can use built-in (int), (string), (bool), and other statements (i dont know how they are called). When casting int type with (int) o a string var it was done 40% faster than using intval() function. But I read that in some cases it can reach up to 350%. So for the sake of your scripts dont use functions to typecast.

$("#mfreak").find(".head brain").clone();

Progress:

[|||___________________________] : 5%

Output:

Memory limit reached, unable to complete operation.

Support answer:

Try using a super uber strong mega computer to reach at least 10%.

👋

arnage Lead · 811 posts #2

Depending. 🙂 For examle, when/if is needed, the same value can be float and int so can't define both at 4 and 4.4 but intval() is ok with both values. 🙂

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
mFreak Developer · 66 posts #3

arnage wrote: Depending. 🙂 For examle, when/if is needed, the same value can be float and int so can't define both at 4 and 4.4 but intval() is ok with both values. :)

you can still use (int) even in if statements. The point is that its faster, and it does the same work.

$("#mfreak").find(".head brain").clone();

Progress:

[|||___________________________] : 5%

Output:

Memory limit reached, unable to complete operation.

Support answer:

Try using a super uber strong mega computer to reach at least 10%.

👋

arnage Lead · 811 posts #4

I didn't mention if() anywhere. 🙂 (int) is int, for example 4, (float) is float, for example 4.4, and intval() is both. So it doesn't do the same thing. Also intval() is commonly used for conversion, not just expected values like (int). 🙂

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
mFreak Developer · 66 posts #5

arnage wrote: I didn't mention if() anywhere. 🙂 (int) is int, for example 4, (float) is float, for example 4.4, and intval() is both. So it doesn't do the same thing. Also intval() is commonly used for conversion, not just expected values like (int). :)

oh, you were thinking about the intvals second param, base conversion.yup i know now what were you thinking with that float, sorry i was a bit confused earlier. Well that issue is beyond reach of my thread. I just wanted to tell some coders here how to optimize scripts, as i saw many use intval to convert strings to ints(mostly when fetcing ids from get), and its faster with (int) 🙂 .

$("#mfreak").find(".head brain").clone();

Progress:

[|||___________________________] : 5%

Output:

Memory limit reached, unable to complete operation.

Support answer:

Try using a super uber strong mega computer to reach at least 10%.

👋

arnage Lead · 811 posts #6

You are right, it is one of cases when intval shouldn't be used insted int, simply because if "something unusual" is pased via url intval will convert it but int will set it to 0. 🙂 Meybe to be intval() used with abs()... But here would be your question of speed. 🙂

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close