The bitarray C extension stores arrays of small integers (1, 8, 16, 32Sounds very useful, thank you, Eric !
or 64 bits, signed or unsigned) packed in memory that looks and behaves
like an ordinary Tcl list. To the rest of Tcl a bitarray IS a list:
lindex, lset, lrange, lreplace, linsert, foreach, "in", lsort, lsearch, join, {*}$a all work on a bitarrary.
The bitarray C extension stores arrays of small integers (1, 8, 16, 32 or 64 bits, signed or unsigned) packed in memory that looks and behaves like an ordinary Tcl list. To the rest of Tcl a bitarray IS a list: lindex, lset, lrange, lreplace, linsert, foreach, "in", lsort, lsearch, join, {*}$a all work on a bitarrary.
.....
They work a 64-bit word at a time, and the logical and relational operators use SSE2 for the 8-, 16- and 32-bit widths on x86-64 (on by default; one build switch turns it off). The table below is one million elements, microseconds per call, measured on Windows with Visual C++ /O2 against the same job done on a plain list with an ordinary Tcl loop. The numbers are from running extras/listbench.tcl on a Windows run.
operation plain list bitarray speed-up-approx
a AND b (1-bit arrays) 87,347 7.9 11,000x ....
"> 1000" on a 16-bit array 250,769 315 800x
Questions, bug reports and criticism are welcome. Mit Licence.
-Eric
et99 <[email protected]> posted:
The bitarray C extension stores arrays of small integers (1, 8, 16, 32 or 64 bits, signed or unsigned) packed in memory that looks and behaves like an ordinary Tcl list. To the rest of Tcl a bitarray IS a list: lindex, lset, lrange, lreplace, linsert, foreach, "in", lsort, lsearch, join, {*}$a all work on a bitarrary.
.....
They work a 64-bit word at a time, and the logical and relational operators use SSE2 for the 8-, 16- and 32-bit widths on x86-64 (on by default; one build switch turns it off). The table below is one million elements, microseconds per call, measured on Windows with Visual C++ /O2 against the same job done on a plain list with an ordinary Tcl loop. The numbers are from running extras/listbench.tcl on a Windows run.
operation plain list bitarray speed-up-approx
a AND b (1-bit arrays) 87,347 7.9 11,000x
....
"> 1000" on a 16-bit array 250,769 315 800x
Questions, bug reports and criticism are welcome. Mit Licence.
-Eric
It seems astonishing, almost incredible, especially for the use on digital signals or
analog signals (after being converted to integer). What are land, lnot ...? Are they just mnemonics you used for your explanations ?
Olivier.
Hi Olivier:
The speed comes from being done in C instead of a Tcl loop, 64 bits at a time (and with SSE2 for some of the 8-, 16- and 32-bit operators). And yes, once the samples are integers, a threshold test gives a 1-bit array that you can combine with other tests and counting.
...
...
The benchmark that produced the table is extras/listbench.tcl in the repository, and I would be glad to hear what numbers you get on your own machine.
Thanks for your interest,
Eric
* et99 <[email protected]>
| The answer to your question is that they aren't mnemonics, they are
| the operator words of bitarray op. 'land' is a logical 'and' along
| with two other logicals: 'lor' and 'lnot'.
Being curious: 'and' for two bitarrays seems logical (do 'and' for every
bit in each array) , but what is 'land' in this respect? Does this use
the whole array (1 if any bit is on, 0 else) and do the "logical and" for these two?
| and the bitarray times, 7.9 microseconds for 1-bit arrays and 60 for
| 8-bit ones, are for the single command:
| bitarray op X = X and $Z ;# updates X in place: X = X and Z
I would have expected
bitarray op X = _$_X and $Z
("_" for emphasis) - is this a typo in the posting or a misunderstanding
on my side?
Interesting project!
R'
et99 <[email protected]> posted:
Hi Olivier:
The speed comes from being done in C instead of a Tcl loop, 64 bits at a time (and with SSE2 for some of the 8-, 16- and 32-bit operators). And yes, once the samples are integers, a threshold test gives a 1-bit array that you can combine with other tests and counting.
...
Tcl being in C the comparison is fair, and it is much much faster.
And your solution is quite usable in my opinion.
...
The benchmark that produced the table is extras/listbench.tcl in the repository, and I would be glad to hear what numbers you get on your own machine.
Thanks for your interest,
Eric
Unfortunately I am more comfortable with heat, magnetics, hydraulics, power electronics
... So that apart from the assembly language paragraph (that has not changed
since ages, and could decipher), I cannot be constructive.
But soon I will have interest in VHDL and simulation, so
your result could save me if what I am doing in pure Tcl is too slow.
And I wonder what you will discover with AI next time ? There seems to have
a hype on security, but not on pure speed execution, hopefully you can help in improving Tcl speed.
Olivier.
PS : AI when it is reasonably used is a good tool for small projects, but
I hope you will never ask ( in fact it will be so expensive ! ) Claude :
Hey Claude, fork a new Tcl that is 10x faster on the whole set of commands" :-D !
I had only used it 4-5 times, the simple Chatgpt console, for procedure dealing
with images in Tcl. It works, but it is not so clever.
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,142 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 92:10:50 |
| Calls: | 14,704 |
| Calls today: | 2 |
| Files: | 186,497 |
| D/L today: |
2,083 files (617M bytes) |
| Messages: | 2,551,641 |