views:

103

answers:

4

I'm trying to make my program faster, so I'm profiling it. Right now the top reason is:

566    1.780    0.003    1.780    0.003 (built-in method decode)

What is this exactly? I never call 'decode' anywhere in my code. It reads text files, but I don't believe they are unicode-encoded.

+2  A: 

Most likely, this is the decode method of string objects.

Martin v. Löwis
I'm pretty sure it is - but any idea why it's taking up so much time / when it's being called? I never call it explicitly
Claudiu
That is impossible to answer without code.
Lennart Regebro
+1  A: 

Presumably this is str.decode ... search your source for "decode". If it's not in your code, look at Python library routines that show up in the profile results. It's highly unlikely to be to be anything to do with cPickle. Care to show us a few more "reasons", preferably with the column headings, to give us a wider view of your problem?

Can you explain the connection between "using cPickle" and "some test cases would run faster"?

You left the X and Y out of "Is there anything that will do task X faster than resource Y?" ... Update so you were asking about cPickle. What are you using for the (optional) protocol arg of cPickle.dump() and/or cPickle.dumps() ?

John Machin
i meant 'is there anything that will do what cPickle does, but faster'. nvm about the test cases and such, maybe they're not related
Claudiu
A: 

I believe decode is called anytime you are converting unicode strings into ascii strings. I am guessing you have a large amount of unicode data. I'm not sure how the internals of pickle work, but it sounds like that unicode data gets converted to ascii when pickled?

Peter Shinners
@Peter Shinners and two upvoters: unicode_obj.encode('ascii') -> str_obj *not* *decode* aarrgghh!
John Machin
+1  A: 

(Answering @Claudiu's latest question, weirdly hidden in a commennt...?!-)... To really speed up pickling, try unladen swallow -- most of its ambitious targets are still to come, but it DOES already give at least 20-25% speedup in pickling and unpickling.

Alex Martelli
oh neat, I heard about this before. great name, too. (about the question:: I 'hid' it cause I thought the pickling didn't have to do with the decoding, but maybe I was wrong?)
Claudiu
decode would not happen during pickling (encoding would, if anything), but it might happen during unpickling -- do you only pickle and never unpickle?
Alex Martelli