| Deutsch English Français Italiano |
|
<52b7365dfcec510a4600ab6b0daad03c@www.novabbs.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: neumann@wu-wien.ac.at (gustafn)
Newsgroups: comp.lang.tcl
Subject: Re: Performance of list / array / dict compared
Date: Mon, 19 Aug 2024 08:35:29 +0000
Organization: novaBBS
Message-ID: <52b7365dfcec510a4600ab6b0daad03c@www.novabbs.com>
References: <96ddc76b99ce6bf7397a5158fece845f@www.novabbs.com> <JFmwO.111824$KuXa.56578@fx44.iad> <dd2b683b86c31d62c2fc9919ffa6179e@www.novabbs.com> <v9t9ka$2euft$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="3097296"; mail-complaints-to="usenet@i2pn2.org";
posting-account="p+4Dm87JGuJs8u5UavFXrfM1jr+8eOP5kauH444y/E8";
User-Agent: Rocksolid Light
X-Rslight-Posting-User: 5290a2eaf9a37a468f724ff23c0a97a2f047b83d
X-Rslight-Site: $2y$10$JTGnLlzcVkOwQiVeyu4AweKHwxkwgEHas.UM/SLZQ9aEiCN2o/b3O
X-Spam-Checker-Version: SpamAssassin 4.0.0
Bytes: 2940
Lines: 65
Hi RodionGork,
I took a quick look at the "primes" examples in your comparison on the
GitHub page.
Using any data structures other than lists does not make sense for this
example.
One could get an improvement of about 5% by putting the outer loop into
a proc.
Most of the time in this example is spent in the "is_prime" proc.
One can get much bigger improvements by using critcl for the is_prime
function (see below):
baseline list 1766907.44 100.00
loop proc 1689220.00 95.60
is_prime_list_c 118298.50 6.70
This is in the spirit of thinking in "system languages" and "glue
languages"
by John Ousterhout, where one should find the right mix for the
applications,
when performance matters.
all the best
-g
===================================================================================
package require critcl
critcl::cproc is_prime_list_c {Tcl_Interp* interp list primes int x} int
{
int i;
for (i=0; i<primes.c; i++) {
int d;
if (Tcl_GetIntFromObj(interp, primes.v[i], &d) != TCL_OK) {
fprintf(stderr, "list element is not an integer: '%s'\n",
Tcl_GetString(primes.v[i]));
}
if (d*d > x) return 1;
if (x%d == 0) return 0;
}
return -1;
}
critcl::load
===================================================================================
===================================================================================
proc run_list_c {} {
set primes {2 3 5 7}
set n $::env(MAXN)
for {set i 9} {1} {incr i 2} {
if {[is_prime_list_c $primes $i]} {
lappend primes $i
if {[llength $primes] == $n} {
puts "primes\[$n\] = $i"
break
}
}
}
}
===================================================================================