Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6085411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:38:09+00:00 2026-05-23T11:38:09+00:00

What is the fastest way of iterating over an array in F#? Using Array.[index]

  • 0

What is the fastest way of iterating over an array in F#? Using Array.[index] seems to create (by looking at the assembly produce in Release mode) call asm instruction.
Is there a way to avoid this ?
Thanks

120:             me.[i] <- me.[i] ||| you.[i]
    0000005b 8B 45 F8             mov         eax,dword ptr [ebp-8] 
    0000005e 8B 55 E0             mov         edx,dword ptr [ebp-20h] 
    00000061 3B 42 04             cmp         eax,dword ptr [edx+4] 
    00000064 72 05                jb          0000006B 
    00000066 E8 35 CD B9 65       call        65B9CDA0 
    0000006b 8B 4C C2 08          mov         ecx,dword ptr [edx+eax*8+8] 
    0000006f 8B 5C C2 0C          mov         ebx,dword ptr [edx+eax*8+0Ch] 
    00000073 8B 45 F8             mov         eax,dword ptr [ebp-8] 
    00000076 8B 55 DC             mov         edx,dword ptr [ebp-24h] 
    00000079 3B 42 04             cmp         eax,dword ptr [edx+4] 
    0000007c 72 05                jb          00000083 
    0000007e E8 1D CD B9 65       call        65B9CDA0 
    00000083 0B 4C C2 08          or          ecx,dword ptr [edx+eax*8+8] 
    00000087 0B 5C C2 0C          or          ebx,dword ptr [edx+eax*8+0Ch] 
    0000008b 89 4D EC             mov         dword ptr [ebp-14h],ecx 
    0000008e 89 5D F0             mov         dword ptr [ebp-10h],ebx 
    00000091 8B 45 F8             mov         eax,dword ptr [ebp-8] 
    00000094 8B 55 E0             mov         edx,dword ptr [ebp-20h] 
    00000097 3B 42 04             cmp         eax,dword ptr [edx+4] 
    0000009a 72 05                jb          000000A1 
    0000009c E8 FF CC B9 65       call        65B9CDA0 
    000000a1 8B 4D EC             mov         ecx,dword ptr [ebp-14h] 
    000000a4 8B 5D F0             mov         ebx,dword ptr [ebp-10h] 
    000000a7 89 4C C2 08          mov         dword ptr [edx+eax*8+8],ecx 
    000000ab 89 5C C2 0C          mov         dword ptr [edx+eax*8+0Ch],ebx  

Update : using Array.iter give me :

   122:           me |> Array.iteri (fun i elem -> me.[i] <- me.[i] ||| you.[i] )
0000003a B9 18 26 70 00       mov         ecx,702618h 
0000003f E8 7C 53 A5 FF       call        FFA553C0 
00000044 89 45 E0             mov         dword ptr [ebp-20h],eax 
00000047 FF 75 E4             push        dword ptr [ebp-1Ch] 
0000004a 8B 55 E8             mov         edx,dword ptr [ebp-18h] 
0000004d 8B 4D E0             mov         ecx,dword ptr [ebp-20h] 
00000050 FF 15 00 26 70 00    call        dword ptr ds:[00702600h] 
00000056 8B 55 E8             mov         edx,dword ptr [ebp-18h] 
00000059 8B 4D E0             mov         ecx,dword ptr [ebp-20h] 
0000005c 8B 05 DC 27 70 00    mov         eax,dword ptr ds:[007027DCh] 
00000062 6A 00                push        0 
00000064 6A 00                push        0 
00000066 6A 01                push        1 
00000068 50                   push        eax 
00000069 83 3D 88 A2 63 66 00 cmp         dword ptr ds:[6663A288h],0 
00000070 74 09                je          0000007B 
00000072 51                   push        ecx 
00000073 52                   push        edx 
00000074 E8 C2 DE C1 65       call        65C1DF3B 
00000079 5A                   pop         edx 
0000007a 59                   pop         ecx 
0000007b E8 A7 5C 96 65       call        65965D27 
00000080 CC                   int         3 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:38:10+00:00Added an answer on May 23, 2026 at 11:38 am

    As a guess, you’ve obtained disassembled source while running under the debugger. Presence of debugger prevents a number of JIT optimizations. As a demonstration:

    let assign (a : _[]) (b : _[]) =
        for i = 0 to a.Length do
            a.[i] <- b.[i] 
            System.Diagnostics.Trace.Assert(false)
            |> ignore
    
    assign [|1|] [|0|]
    

    Release, with debugger:

            a.[i] <- b.[i] 
    0000003b  mov         eax,dword ptr [ebp-8] 
    0000003e  mov         edx,dword ptr [ebp-14h] 
    00000041  cmp         eax,dword ptr [edx+4] 
    00000044  jb          0000004B 
    00000046  call        762798A8 
    0000004b  mov         eax,dword ptr [edx+eax*4+8] 
    0000004f  mov         dword ptr [ebp-0Ch],eax 
    00000052  mov         eax,dword ptr [ebp-8] 
    00000055  mov         edx,dword ptr [ebp-10h] 
    00000058  cmp         eax,dword ptr [edx+4] 
    0000005b  jb          00000062 
    0000005d  call        762798A8 
    00000062  mov         ecx,dword ptr [ebp-0Ch] 
    00000065  mov         dword ptr [edx+eax*4+8],ecx 
    ....
    

    Release, without debugger (use ctrl+f5 for run, press Retry when Assert window pops up and only then attach debugger to process)

            a.[i] <- b.[i] 
    00000017  cmp         esi,dword ptr [ebx+4] 
    0000001a  jae         00000043 
    0000001c  mov         eax,dword ptr [ebx+esi*4+8] 
    00000020  cmp         esi,dword ptr [edi+4] 
    00000023  jae         00000043 
    00000025  mov         dword ptr [edi+esi*4+8],eax 
    ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking the fastest way to draw thousands of individually calculated pixels directly
What's the fastest way using either DOS scripting or PowerShell to run this simple
I'm looking for the fastest way to do an integer division in php. for
What is the fastest way to sort an array of whole integers bigger than
What is the fastest way to convert a simple array to an associative array
What's a fastest way to implement array subtraction? For example: array a1 = [1,
What is the fastest way to unwrap array into rows in PostgreSQL? For instance,
What is the fastest way to lookup the index of a value in sorted
What is the fastest way to sum up an array in JavaScript? A quick
I need fastest way to find the values in array A that their mods

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.