two slow substr() performance

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kim Gijung

    two slow substr() performance

    hi all

    i looped bellow code around 100 times and the results are following.
    each reaults are millisecond.

    is the substr takes much performance?
    and don't know why the time it takes getting fast lineally.
    can anybody suggest better function or way instead of substr function.

    $pkt = substr($pkt, 65 + 3 + (4 * 3) + 65 + 65 + 65 + 17 + 17 + 6 + 1
    + (4 * 3) + 65 + 3);


    0.880004882812
    1.64990234375
    0.860107421875
    0.85498046875
    0.852905273438
    0.85791015625
    0.872924804688
    0.844970703125
    0.839965820312
    0.85302734375
    0.850952148438
    0.986938476562
    0.8359375
    0.828002929688
    0.824951171875
    0.820922851562
    0.817993164062
    0.817993164062
    0.815063476562
    0.80908203125
    0.904907226562
    0.802001953125
    0.799072265625
    0.796020507812
    0.7919921875
    0.827026367188
    0.786010742188
    0.780029296875
    0.787963867188
    0.777954101562
    0.77392578125
    0.77099609375
    1.03601074219
    0.776977539062
    0.762084960938
    0.760009765625
    0.755981445312
    9.50793457031
    0.755004882812
    0.746948242188
    0.755981445312
    0.741088867188
    0.738037109375
    0.739013671875
    0.73095703125
    0.751953125
    0.72705078125
    0.723022460938
    1.55493164062
    0.710083007812
    0.706909179688
    0.703002929688
    0.701049804688
    0.699096679688
    0.695922851562
    0.692993164062
    0.690063476562
    1.14599609375
    0.68603515625
    0.681030273438
    0.677001953125
    0.675048828125
    0.776977539062
    0.669921875
    0.6669921875
    0.672973632812
    0.658935546875
    0.656982421875
    0.654907226562
    0.651977539062
    0.666015625
    0.64501953125
    0.652954101562
    0.7890625
    0.636962890625
    0.632934570312
    0.629028320312
    0.629028320312
    0.6240234375
    0.626953125
    0.629028320312
    0.617065429688
    0.614990234375
    0.609985351562
    0.610961914062
    0.608032226562
    0.60107421875
    0.598022460938
    0.598022460938
    0.595947265625
    0.598999023438
    0.590942382812
    0.5849609375
    0.58203125
    0.578979492188
    0.703979492188
    0.572021484375
    0.570068359375
    0.587036132812
    0.56201171875
    0.720947265625
    0.558959960938
    1.01806640625
    0.545043945312
    0.541015625
    0.547973632812
    0.531982421875
    0.545043945312
    0.536987304688
    0.531982421875
    0.526000976562
    0.533935546875
    0.527954101562
    0.51806640625
    0.515014648438
    0.512939453125
    0.508911132812
    0.506958007812
    0.515014648438
    0.503051757812
    0.497924804688
    0.494018554688
    0.490966796875
    0.488037109375
    0.484985351562
    0.484008789062
    0.48095703125
    0.477905273438
    0.491943359375
    0.470947265625
    0.468017578125
    0.466064453125
    0.465942382812
    0.4619140625
    0.4580078125
    0.454956054688
    0.453002929688
    0.447998046875
    0.446044921875
    0.442993164062
    0.439086914062
    0.435913085938
    0.431030273438
    0.4169921875
    0.4130859375
    0.421020507812
    0.412963867188
    0.410034179688
    0.403930664062
    0.401000976562
    0.39599609375
    0.405029296875
    0.390991210938
    0.390014648438
    0.384033203125
    0.383056640625
    0.37890625
    0.376953125
    0.373046875
    0.369018554688
    0.3740234375
    0.365966796875
    0.363037109375
    0.35302734375
    0.35302734375
    0.347045898438
    0.344970703125
    0.340942382812
    0.338989257812
    0.3349609375
    0.330932617188
    0.326049804688
    0.343994140625
    0.325073242188
    0.319091796875
    0.31494140625
    0.310913085938
    0.30908203125
    0.305053710938
    0.300048828125
    0.296997070312
    0.299926757812
    0.295043945312
    0.2890625
    0.285034179688
    0.285034179688
    0.276000976562
    0.279052734375
    0.281982421875
    0.26806640625
    0.261962890625
    0.258056640625
    0.254028320312
    0.248901367188
    0.243041992188
    0.240966796875
    0.255981445312
    0.194946289062
    0.193969726562
    0.197998046875
    0.192016601562
    0.18896484375
    0.196044921875
    0.178955078125
    0.177001953125
    0.177978515625
    0.1650390625
    0.161987304688
    0.161010742188
    0.157958984375
    0.156005859375
    0.156005859375
    0.151000976562
    0.156005859375
    0.14697265625
    0.140991210938
    0.137939453125
    0.132934570312
    0.130981445312
    0.256958007812
    0.1240234375
    0.121948242188
    0.119995117188
    0.115966796875
    0.201049804688
    0.114990234375
    0.119018554688
    0.118041992188
    0.114013671875
    0.110107421875
  • Andy Hassall

    #2
    Re: two slow substr() performance

    On 19 Aug 2004 01:42:40 -0700, gijung@amicus.c o.kr (Kim Gijung) wrote:
    [color=blue]
    >i looped bellow code around 100 times and the results are following.
    >each reaults are millisecond.
    >
    >is the substr takes much performance?
    >and don't know why the time it takes getting fast lineally.
    >can anybody suggest better function or way instead of substr function.
    >
    >$pkt = substr($pkt, 65 + 3 + (4 * 3) + 65 + 65 + 65 + 17 + 17 + 6 + 1
    >+ (4 * 3) + 65 + 3);[/color]

    The times are decreasing because you're copying all but the first 316 bytes
    each time, so there's less and less data to copy.

    Do you really mean to be making loads of copies of the entire original data?
    Or do you just want to read it 316 bytes at a time? If the latter, then
    something like:

    for ($i=0; $i<strlen($pkt) ; $i += 316)
    {
    $something = substr($pkt, $i, 316);
    // do something with $something
    }

    --
    Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
    <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

    Comment

    Working...