F # performance error?

let test1fun x = [for i in 1..x-> i]

let test2fun x y= [for i in 1..x
                    do for i in 1..y-> i]

let  singlesearcher i =
    let rec searcher j agg =
        if j > i 
        then agg 
        else searcher (j+1) (i::agg)
    searcher 1 []


let  doublesearcher i j =
    let rec searcher k l agg =
        if k > i 
        then searcher 1 (l+1) agg
        else if l > j 
             then agg
             else searcher (k+1) l ((k,l)::agg)
    searcher 1 1 []

execution above C # time and 10000 for all inputs gives

list comprehension/singlesearcher-> negligable
cross product -> 320
list comprehension crossproduct -> 630

Why is the sublist view more than double the functional version?

+3
source share
1 answer

Yes. List accounting is usually slower than directly using a list or an F # array. (On my car, I also find similar terms with you.)

See how they are implemented. The list comprehension version is actually quite complicated:

  • the sequence / IEnumerable<int>is created using the syntax of understanding. This is just a lazy sequence, there is little time.

  • F #, - Seq.toList. . HasNext MoveNext switch (state), , . .

doublesearcher . , , .

, , . , . . , , , , , .

+6

All Articles