While this seems to be the case in Python 2.5 (without a built-in json
class), it isn't true in Python 2.7 (from my tests at least):
############
import string, random, profile, json
#import simplejson as json
def randomString(length):
return ''.join(random.choice(string.ascii_uppercase + string.digits)
for x in range(length))
t = {}
for x in range(500):
t[randomString(8)] = randomString(12)
profile.run("eval(repr(t))")
profile.run("json.loads(json.dumps(t))")
############
Using the simplejson class resulted in code significantly slower
(15-20x slower). However, using the built-in json class in Python 2.7
resulted in code slightly faster than repr() (3-5x faster).
With the upcoming support for 2.7, I'd suggest keeping json encoding.
It's also more portable "as-is" although it wouldn't be such a hard
task to switch between the two.