- string randomize <string> : mélange string de façon aléatoire
Code :
% string randomize abcdef
dfecba
- string sort ?-option value ...? <string> : utilise la commande lsort de façon a classer string dans l'ordre désiré (en fonction des options spécifié)
(cf man lsort pour plus d info sur les options)
Y'a-t-il une raison particulière à utiliser set string plutôt que return $string ?
__________
Pour une librairie de ce genre, la rapidité d'exécution est cruciale et quelques optimisations seraient les bienvenues. Même si ça n'a l'air de rien, quelques µs gagnées sur une proc exécutée plusieurs fois par seconde peuvent avoir un effet sensible.
Voici à quoi je fais allusion :
tcl
expr{$string==""}
pour tester une condition impliquant une string, eq et ne sont plus rapides que == et != (et inversement pour tester une équivalence numérique), donc :
On économise ainsi quelques instructions.
A noter aussi que ::tcl::string::replace s'exécute plus rapidement que string replace car ça épargne à l'interpréteur la peine de devoir localiser le namespace.
Même chose pour les string length qui deviendront des ::tcl::string::length et les string empty qui deviendront des ::tcl::string::empty.
__________
tcl
set j [expr{int(rand()*$len)}]setstring[string xchang $string$i$j]
Citation :Y'a-t-il une raison particulière à utiliser set string plutôt que return $string ?
et bien set est la syntaxe par défaut de tcl sachant que $ est un raccourci vers set "return $string" est équivalent a "return [set string]"
sinon == ou eq on un temps d'exécution strictement identique
Citation :TCL :
set string [string replace $string $index2 $index2 $tmp]
set string [string replace $string $index1 $index1 $tmp2]
deviendrait
TCL :
return [::tcl::string::replace [::tcl::string::replace $string $index2 $index2 $tmp] $index1 $index1 $tmp2]
On économise ainsi quelques instructions.
A noter aussi que ::tcl::string::replace s'exécute plus rapidement que string replace car ça épargne à l'interpréteur la peine de devoir localiser le namespace.
Même chose pour les string length qui deviendront des ::tcl::string::length et les string empty qui deviendront des ::tcl::string::empty.
j'aime bien garder un code claire d'où l utilisation de 2 lignes.
Par contre pour l'utilisation du path complet ca pourrait être une bonne idée, il y a un gain de 2us / 50us en moyenne
voila j ai modifié les path,
sur un "string randomize 0123456789" le gain de performance est proche des 80% (à cause de la boucle surement)
je ne pensais pas qu'on y gagnerai autant
Citation :avec ==
% time {::tcl::string::empty ""} 100000
1.88144 microseconds per iteration
% time {::tcl::string::empty ""} 100000
1.86438 microseconds per iteration
% time {::tcl::string::empty ""} 100000
1.89402 microseconds per iteration
% time {::tcl::string::empty ""} 100000
1.86838 microseconds per iteration
% time {::tcl::string::empty ""} 100000
1.87231 microseconds per iteration
% time {::tcl::string::empty ""} 100000
1.87639 microseconds per iteration
% time {::tcl::string::empty aaa} 100000
2.14479 microseconds per iteration
% time {::tcl::string::empty aaa} 100000
2.1215 microseconds per iteration
% time {::tcl::string::empty aaa} 100000
2.12854 microseconds per iteration
% time {::tcl::string::empty aaa} 100000
2.12112 microseconds per iteration
% time {::tcl::string::empty aaa} 100000
2.13864 microseconds per iteration
% time {::tcl::string::empty aaa} 100000
2.12714 microseconds per iteration
Citation :avec eq
% time {::tcl::string::empty ""} 100000
1.97091 microseconds per iteration
% time {::tcl::string::empty ""} 100000
1.98191 microseconds per iteration
% time {::tcl::string::empty ""} 100000
1.99542 microseconds per iteration
% time {::tcl::string::empty ""} 100000
1.97693 microseconds per iteration
% time {::tcl::string::empty ""} 100000
1.96448 microseconds per iteration
% time {::tcl::string::empty ""} 100000
1.98486 microseconds per iteration
% time {::tcl::string::empty aaa} 100000
1.90619 microseconds per iteration
% time {::tcl::string::empty aaa} 100000
1.90897 microseconds per iteration
% time {::tcl::string::empty aaa} 100000
1.91097 microseconds per iteration
% time {::tcl::string::empty aaa} 100000
1.90607 microseconds per iteration
% time {::tcl::string::empty aaa} 100000
1.93027 microseconds per iteration
% time {::tcl::string::empty aaa} 100000
1.90746 microseconds per iteration