M
Marc 'BlackJack' Rintsch
Well D code is compiled into machine code that runs via a VM.
About which D are we talking here? Not digital mars' successor to C++,
right!?
Ciao,
Marc 'BlackJack' Rintsch
Well D code is compiled into machine code that runs via a VM.
About which D are we talking here? Not digital mars' successor to C++,
right!?
Ciao,
Marc 'BlackJack' Rintsch
George Sakkis said:It has to do with the input string length; try multiplying it by 10 or
100. Below is a more complete benchmark; for largish strings, the imap
version is the fastest among those using the original algorithm. Of
course using a lookup table as Diez showed is even faster. FWIW, here
are some timings (Python 2.5, WinXP):scramble: 1.818
scramble_listcomp: 1.492
scramble_gencomp: 1.535
scramble_map: 1.377
scramble_imap: 1.332
scramble_dict: 0.817
scramble_dict_map: 0.419
scramble_dict_imap: 0.410
I added another one:
import string
scramble_translation = string.maketrans(''.join(chr(i) for i in xrange
(256)), ''.join(chr(i|0x80) for i in xrange(256)))
def scramble_translate(line):
return string.translate(line, scramble_translation)
...
funcs = [scramble, scramble_listcomp, scramble_gencomp,
scramble_map, scramble_imap,
scramble_dict, scramble_dict_map, scramble_dict_imap,
scramble_translate
]
and I think I win:
scramble: 1.949
scramble_listcomp: 1.439
scramble_gencomp: 1.455
scramble_map: 1.470
scramble_imap: 1.546
scramble_dict: 0.914
scramble_dict_map: 0.415
scramble_dict_imap: 0.416
scramble_translate: 0.007
Yes, Digital Mars D is what I was referring to and yes I know D is not
as efficient as C++.
as efficient as C++. If I knew of a good C++ compiler that is not
from Microsoft that works natively with Windows I would be happy to
consider using it.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.