Re: Performance of list / array / dict compared

Liste des GroupesRevenir à cl tcl 
Sujet : Re: Performance of list / array / dict compared
De : neumann (at) *nospam* wu-wien.ac.at (gustafn)
Groupes : comp.lang.tcl
Date : 19. Aug 2024, 09:35:29
Autres entêtes
Organisation : novaBBS
Message-ID : <52b7365dfcec510a4600ab6b0daad03c@www.novabbs.com>
References : 1 2 3 4
User-Agent : Rocksolid Light
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
            }
        }
    }
}
===================================================================================

Date Sujet#  Auteur
18 Aug 24 * Performance of list / array / dict compared5RodionGork
18 Aug 24 +* Re: Performance of list / array / dict compared3RodionGork
18 Aug 24 i`* Re: Performance of list / array / dict compared2Rich
19 Aug 24 i `- Re: Performance of list / array / dict compared1gustafn
18 Aug 24 `- Re: Performance of list / array / dict compared1Rich

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal