Hi all !

I don't understand this argument. My test is just an example of how an immutable array class works. There are implementations for many common languages.

As we can see the array is 10 million integers or 40 MB. Using memcpy on one thread it could take 40/(1826 MB/s) or 22 ms to copy this array. Using an immutable array class you could copy it in 12 microseconds. What makes memcpy better?

http://stackoverflow.com/questions/4260602/how-to-increase-performance-of-memcpy

Cheers,

Erling Hellenäs


On 2016-10-06 16:16, Xiao-Yong Jin wrote:
Implementation dependent.
Irrelevant.

On Oct 6, 2016, at 3:33 AM, Erling Hellenäs <[email protected]> wrote:

Hi all !

This test with an immutable list class shows how you can get a copy with one 
changed element in 12 microseconds while the same copy with one changed element 
with a non-immutable array takes 15 milliseconds.

The tests are repeated, but it's the second test that counts.

   let mutable a = ImmList<int>.Empty
    let mutable b = null;
    let mutable c = null;
    a <- a.AddFirstRange([1 .. 10000000])
    let stopWatch = System.Diagnostics.Stopwatch.StartNew()
    b <- a.Update(5000000,-1);
    stopWatch.Stop()
    printfn "%f" stopWatch.Elapsed.TotalMilliseconds
    //6.442300
    printfn "%A %A" (a.TryGet(5000000)) (b.TryGet(5000000));
    //5000001 -1
    let stopWatch = System.Diagnostics.Stopwatch.StartNew()
    c <- a.Update(5000000,-1);
    stopWatch.Stop()
    printfn "%f" stopWatch.Elapsed.TotalMilliseconds
    //0.011900
    let a = [|1 .. 10000000|]
    let stopWatch = System.Diagnostics.Stopwatch.StartNew()
    let b = Array.copy a;
    b.[5000000] <- -1
    stopWatch.Stop()
    printfn "%f" stopWatch.Elapsed.TotalMilliseconds
    //15.108700
    printfn "%i %i" a.[5000000] b.[5000000];
    //5000001 -1
    let stopWatch = System.Diagnostics.Stopwatch.StartNew()
    let c = Array.copy a;
    c.[5000000] <- -1
    stopWatch.Stop()
    printfn "%f" stopWatch.Elapsed.TotalMilliseconds
    //14.760200

Cheers,

Erling Hellenäs


On 2016-10-05 02:34, Xiao-Yong Jin wrote:
On Oct 4, 2016, at 2:01 PM, Louis de Forcrand <[email protected]> wrote:

Maybe add a third setting to 9!:53 which copies a at the start of a tacit verb 
involving in place operations?
This is a good compromise between speed and sensible intuition.
I guess a memcpy only when in-place-operation is detected wouldn't be slower in 
general than previous non-in-place operations.
This could certainly be the default option.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to