; _$ (SplitStrWithStr "$#*" "$#*ABC$#*")
; ("$#*" "ABC" "$#*" "ABC$#*")
; _$ (SplitStrWithStr "$#*" "$#*ABC")
; ("$#*" "ABC")
; _$ (SplitStrWithStr "$#*" "ABC$#*")
; ("ABC" "$#*")
; _$ (SplitStrWithStr "$#*" "$#*ABC$#*DEF$#*GHIJKL$#*MNOP$#*")
; ("$#*" "ABC" "$#*" "DEF" "$#*" "GHIJKL" "$#*" "MNOP" "$#*" "MNOP$#*")
; _$ (SplitStrWithStr "$#*" "ABC$#*DEF$#*GHIJKL$#*MNOP")
; ("ABC" "$#*" "DEF" "$#*" "GHIJKL" "$#*" "MNOP")
; _$
The returns should be as follow:; _$ (SplitStrWithStr "$#*" "$#*ABC$#*")
; ("$#*" "ABC" "$#*")
; _$ (SplitStrWithStr "$#*" "$#*ABC")
; ("$#*" "ABC")
; _$ (SplitStrWithStr "$#*" "ABC$#*")
; ("ABC" "$#*")
; _$ (SplitStrWithStr "$#*" "$#*ABC$#*DEF$#*GHIJKL$#*MNOP$#*")
; ("$#*" "ABC" "$#*" "DEF" "$#*" "GHIJKL" "$#*" "MNOP" "$#*" "MNOP" "$#*")
; _$ (SplitStrWithStr "$#*" "ABC$#*DEF$#*GHIJKL$#*MNOP")
; ("ABC" "$#*" "DEF" "$#*" "GHIJKL" "$#*" "MNOP")
; _$
(defun ALE_String2ListWStrDlm (InpStr StrDlm / SttPos TmpPos DlmLng TmpLst TmpStr)
(cond
( (/= (type InpStr) (type StrDlm) 'STR) )
( (= InpStr StrDlm) '("") )
(T
(setq
DlmLng (strlen StrDlm) SttPos 0
TmpPos (vl-string-search StrDlm InpStr SttPos)
)
(while TmpPos
(if (zerop (- TmpPos SttPos))
(setq TmpLst (cons StrDlm TmpLst))
(setq TmpLst (cons StrDlm (cons (substr InpStr (1+ SttPos) (- TmpPos SttPos)) TmpLst)))
)
(setq
SttPos (+ TmpPos DlmLng)
TmpPos (vl-string-search StrDlm InpStr SttPos)
)
)
(if (= "" (setq TmpStr (substr InpStr (1+ SttPos))))
(reverse TmpLst)
(reverse (cons TmpStr TmpLst))
)
)
)
)
(ALE_String2ListWStrDlm "$#*ABC$#*" "$#*") => ("$#*" "ABC" "$#*")
(ALE_String2ListWStrDlm "$#*ABC" "$#*") => ("$#*" "ABC")
(ALE_String2ListWStrDlm "ABC$#*" "$#*") => ("ABC" "$#*")
(ALE_String2ListWStrDlm "$#*ABC$#*DEF$#*GHIJKL$#*MNOP$#*" "$#*") => ("$#*" "ABC" "$#*" "DEF" "$#*" "GHIJKL" "$#*" "MNOP" "$#*")
(ALE_String2ListWStrDlm "ABC$#*DEF$#*GHIJKL$#*MNOP" "$#*") => ("ABC" "$#*" "DEF" "$#*" "GHIJKL" "$#*" "MNOP")
(defun ALE_String2ListWStrDlm (InpStr StrDlm / SttPos TmpPos DlmLng TmpLst TmpStr)
; 20170611 - version 1.01 - just a little improvement
(cond
( (/= (type InpStr) (type StrDlm) 'STR) )
( (= InpStr StrDlm) (list InpStr) )
(T
(setq DlmLng (strlen StrDlm) SttPos 0)
(if (zerop (setq TmpPos (vl-string-search StrDlm InpStr SttPos)))
(setq
TmpLst (cons StrDlm TmpLst) SttPos DlmLng
TmpPos (vl-string-search StrDlm InpStr SttPos)
)
)
(while TmpPos
(setq
TmpLst (cons StrDlm (cons (substr InpStr (1+ SttPos) (- TmpPos SttPos)) TmpLst))
SttPos (+ TmpPos DlmLng)
TmpPos (vl-string-search StrDlm InpStr SttPos)
)
)
(if (= "" (setq TmpStr (substr InpStr (1+ SttPos))))
(reverse TmpLst)
(reverse (cons TmpStr TmpLst))
)
)
)
)
(defun ALE (s d / p m l o r)
; version for Speed Test
(cond
( (= s d) (list s) )
( (setq l (strlen d))
(if (zerop (setq m (vl-string-search d s 0)))
(setq
o (cons d o) p l
m (vl-string-search d s p)
)
(setq p 0)
)
(while m
(setq
o (cons d (cons (substr s (1+ p) (- m p)) o))
p (+ m l)
m (vl-string-search d s p)
)
)
(if (= "" (setq r (substr s (1+ p))))
(reverse o)
(reverse (cons r o))
)
)
)
)
(setq Keys "$#*" String "$#*ABC$#*DEF$#*GHIJKL$#*MNOP$#*")
Benchmark.lsp | © 2005 Michael Puckett | All Rights Reserved
Elapsed milliseconds / relative speed for 131072 iteration(s):
(ALE STRING KEYS)..........1609 / 1.48 <fastest>
(_FOO_RON KEYS STRING).....2203 / 1.08
(SPLIT STRING KEYS)........2250 / 1.06
(FOO_GILE KEYS STRING).....2375 / 1 <slowest>
SPLIT Benchmarking ...................Elapsed milliseconds / relative speed for 65536 iteration(s):
(SPLIT "$#*" "$#*ABC$#*DEF$#*GHIJKL$...).....1562 / 1.75 <fastest>
(ALE_STRING2LISTWSTRDLM "$#*" "$#*AB...).....1797 / 1.52
(_FOO "$#*" "$#*ABC$#*DEF$#*GHIJKL$#...).....2547 / 1.07
(FOO "$#*" "$#*ABC$#*DEF$#*GHIJKL$#*...).....2735 / 1.00 <slowest>
; 10 forms loaded from #<editor "<Untitled-4> loading...">
_$
Interesting .. I come up with completely different results:...Strange:
(setq Keys "$#*" String "$#*ABC$#*DEF$#*GHIJKL$#*MNOP$#*")
(Benchmark '(
(_foo Keys String)
(foo Keys String)
(split String Keys)
(ALE String Keys)
(_foo Keys String)
(foo Keys String)
(split String Keys)
(ALE String Keys)
) )
Benchmark.lsp | © 2005 Michael Puckett | All Rights Reserved
Elapsed milliseconds / relative speed for 131072 iteration(s):
(ALE STRING KEYS).......1688 / 1.65 <fastest>
(ALE STRING KEYS).......1719 / 1.62
(_FOO KEYS STRING)......2562 / 1.09
(SPLIT STRING KEYS).....2625 / 1.06
(_FOO KEYS STRING)......2656 / 1.05
(FOO KEYS STRING).......2656 / 1.05
(SPLIT STRING KEYS).....2718 / 1.02
(FOO KEYS STRING).......2782 / 1 <slowest>
Benchmark.lsp | © 2005 Michael Puckett | All Rights Reserved
Elapsed milliseconds / relative speed for 131072 iteration(s):
(ALE STRING KEYS).......1641 / 1.59 <fastest>
(ALE STRING KEYS).......1718 / 1.52
(FOO KEYS STRING).......2515 / 1.04
(_FOO KEYS STRING)......2532 / 1.03
(FOO KEYS STRING).......2532 / 1.03
(_FOO KEYS STRING)......2547 / 1.02
(SPLIT STRING KEYS).....2609 / 1
(SPLIT STRING KEYS).....2610 / 1 <slowest>
(_foo Keys String)
(foo Keys String)
(split String Keys)
(ALE String Keys)
$ (benchmark
'((ALE_String2ListWStrDlm "$#*ABC$#*DEF$#*GHIJKL$#*MNOP$#*" "$#*")
(ALE "$#*ABC$#*DEF$#*GHIJKL$#*MNOP$#*" "$#*")
(_foo "$#*" "$#*ABC$#*DEF$#*GHIJKL$#*MNOP$#*")
(split "$#*ABC$#*DEF$#*GHIJKL$#*MNOP$#*" "$#*")
(foo "$#*" "$#*ABC$#*DEF$#*GHIJKL$#*MNOP")
)
)
Benchmarking ...................Elapsed milliseconds / relative speed for 65536 iteration(s):
(ALE "$#*ABC$#*DEF$#*GHIJKL$#*MNOP$#...).....1435 / 1.51 <fastest>
(ALE_STRING2LISTWSTRDLM "$#*ABC$#*DE...).....1576 / 1.38
(FOO "$#*" "$#*ABC$#*DEF$#*GHIJKL$#*...).....1576 / 1.38
(SPLIT "$#*ABC$#*DEF$#*GHIJKL$#*MNOP...).....2060 / 1.05
(_FOO "$#*" "$#*ABC$#*DEF$#*GHIJKL$#...).....2168 / 1 <slowest>
Elapsed milliseconds / relative speed for 131072 iteration(s):
(ALE STRING KEYS).......1656 / 1.56 <fastest>
(ALE STRING KEYS).......1703 / 1.51
(FOO KEYS STRING).......2000 / 1.29
(FOO KEYS STRING).......2000 / 1.29
(_FOO KEYS STRING)......2516 / 1.02
(_FOO KEYS STRING)......2531 / 1.02
(SPLIT STRING KEYS).....2562 / 1.01
(SPLIT STRING KEYS).....2578 / 1 <slowest>
Elapsed milliseconds / relative speed for 131072 iteration(s):
(ALE STRING KEYS).......1688 / 1.52 <fastest>
(ALE STRING KEYS).......1719 / 1.49
(FOO KEYS STRING).......1969 / 1.3
(FOO KEYS STRING).......2000 / 1.28
(_FOO KEYS STRING)......2515 / 1.02
(_FOO KEYS STRING)......2516 / 1.02
(SPLIT STRING KEYS).....2532 / 1.01
(SPLIT STRING KEYS).....2562 / 1 <slowest>
(defun ALE (s d / p m l o r)
; 20170613 - version 1.02
(cond
( (setq l (strlen d) m (vl-string-search d s 0))
(if (zerop m)
(setq
o (cons d o) p l
m (vl-string-search d s p)
)
(setq p 0)
)
(while m
(setq
o (cons d (cons (substr s (1+ p) (- m p)) o))
p (+ m l)
m (vl-string-search d s p)
)
)
(if (= "" (setq r (substr s (1+ p))))
(reverse o)
(reverse (cons r o))
)
)
( (list s) )
)
)
> bench ();;
Elapsed milliseconds for 65536 iterations: 123
val it : unit = ()
Ok... take look at the arguments:I see that now .. guess I should not assume that initial form would follow in testing.Code: [Select](_foo Keys String)
(foo Keys String)
(split String Keys)
(ALE String Keys)
(progn
(setq Keys "$#*" String "$#*ABC$#*DEF$#*GHIJKL$#*MNOP$#*")
(repeat 8 (setq String (strcat String Keys String))) ; la ricorsione arriva fino a 11
(print (strlen String))
(princ)
)
Comando: (strlen String)
8701
Elapsed milliseconds / relative speed for 1024 iteration(s):
(ALE STRING KEYS).....1531 / 4.34 <fastest>
(ALE STRING KEYS).....1531 / 4.34
(FOO KEYS STRING).....6547 / 1.01
(FOO KEYS STRING).....6641 / 1 <slowest>
Interesting enough I fixed the benchmark and Lee's split is still the fastest?you've switched the arguments in Lee's function only once, but should've done it thrice :)
DOH! :)Interesting enough I fixed the benchmark and Lee's split is still the fastest?you've switched the arguments in Lee's function only once, but should've done it thrice :)
(progn
(setq Keys "$#*" String "$#*$#*ABC$#*DEF$#*$#*GHIJKL$#*MNOP$#*$#*")
(repeat 6 (setq String (strcat String Keys String)))
(print (strlen String)) (princ " strlen\n")
(princ)
)
2749 strlen
Elapsed milliseconds / relative speed for 16384 iteration(s):
(ALE STRING KEYS)......2938 / 11.89 <fastest>
(FOO KEYS STRING).....34922 / 1 <slowest>
(defun ALE (s d / p m l o r)
; 20170614 - version 1.03 for adjacent key (d)
(cond
( (setq
l (strlen d) p 0
m (vl-string-search d s 0)
)
(while m
(if (zerop (- m p))
(setq o (cons d o))
(setq o (cons d (cons (substr s (1+ p) (- m p)) o)))
)
(setq
p (+ m l)
m (vl-string-search d s p)
)
)
(if (= "" (setq r (substr s (1+ p))))
(reverse o)
(reverse (cons r o))
)
)
( (list s) )
)
)