packetie
packetie

Reputation: 5069

slow perl performance, why and how to improve

I ran NYTProf on a perl program, I am quite surprised to see the line with "unpack" takes lots of time: (the line got executed 14654 times and took 39.6ms). But the unpack() function itself is quite fast

    $delme1 = substr($data, 47,1)
    $_flags = unpack("C", $delme1);
    # spent  2.98ms making 14654 calls to main::CORE:unpack, avg 203ns/call

Any one knows why such a big overhead?

Thanks

Update 1 See the line with "unpack" call. It says it spent a total of 39.6ms.

enter image description here

Upvotes: 0

Views: 143

Answers (1)

ikegami
ikegami

Reputation: 386551

the line got executed 14654 times and took 39.6ms

No, the line got executed 14654 times and took 2.98ms. Each execution took 203ns on average. Not exactly slow...


You could try using

$_flags = ord(substr($data, 47, 1));

or

$_flags = unpack('x47 C', $data);

There are surely better things to optimize. For example, you would benefit from having a single unpack rather than using multiple calls to substr and unpack.

Upvotes: 2

Related Questions