• [^] # Re: Un bench vaut ce qu'il vaut

    Posté par . En réponse au journal Javascript plus rapide que python ! (une suite possible). Évalué à 3.

    Le 2ème algo. en neko [http://nekovm.org/index]

    var NB_ENTRIES = 10000000
    var HALF_NB_ENTRIES = NB_ENTRIES / 2
    var d = $amake(NB_ENTRIES)

    var i = 2
    while (i <= HALF_NB_ENTRIES)
    {
    var j = 2 * i
    while (j <= NB_ENTRIES)
    {
    if (d[j] == null)
    d[j] = 1 + i
    else
    d[j] += i

    j += i
    }
    i += 1
    }

    i = 1
    while (i <= NB_ENTRIES)
    {
    if (d[i] < NB_ENTRIES && d[d[i]] == i && i <= d[i])
    $print(i, " ", d[i], "\n")

    i += 1
    }


    real 0m48.915s
    user 0m39.157s
    sys 0m0.327s

    Erf...

    PS: J'ai ajouté HALF_NB_ENTRIES parce que j'ai vu dans le bytecode que NB_ENTRIES/2 était calculé à chaque itération.

    The capacity of the human mind for swallowing nonsense and spewing it forth in violent and repressive action has never yet been plumbed. -- Robert A. Heinlein