Code :
>>> from timeit import Timer >>> phrase = "Je voudrais supprimer les espaces dans une chaîne de caractère" >>> t1 = Timer("phrase.replace(' ', '')", "from __main__ import phrase" ) >>> t2 = Timer("''.join(phrase.split())", "from __main__ import phrase" ) >>> t1.repeat(5) [2.708811263072346, 2.7743918581795919, 2.7892361482361947, 2.885014741990112, 2.7131283161064186] >>> t2.repeat(5) [6.9345316711479299, 6.8972708980312269, 6.9507088435471545, 6.8904334304771382, 6.8867523899882173]
|