about typecasting and script optimization

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    about typecasting and script optimization

    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.
    PHP Code:
    $("#mfreak").find(".head brain").clone(); 
    Progress:
    Code:
    [|||___________________________] : 5%
    Output:
    Code:
    Memory limit reached, unable to complete operation.
    Support answer:
    Code:
    Try using a super uber strong mega computer to reach at least 10%.

    #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

    Comment


      #3
      Originally posted by arnage View Post
      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.
      PHP Code:
      $("#mfreak").find(".head brain").clone(); 
      Progress:
      Code:
      [|||___________________________] : 5%
      Output:
      Code:
      Memory limit reached, unable to complete operation.
      Support answer:
      Code:
      Try using a super uber strong mega computer to reach at least 10%.

      Comment


        #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

        Comment


          #5
          Originally posted by arnage View Post
          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) .
          PHP Code:
          $("#mfreak").find(".head brain").clone(); 
          Progress:
          Code:
          [|||___________________________] : 5%
          Output:
          Code:
          Memory limit reached, unable to complete operation.
          Support answer:
          Code:
          Try using a super uber strong mega computer to reach at least 10%.

          Comment


            #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.
            Last edited by arnage; 18.08.12, 09:59.
            <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

            Comment

            Working...
            X