Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Which is faster: array or cursor?
Message
De
10/03/2009 11:45:23
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
10/03/2009 10:22:42
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Divers
Thread ID:
01386748
Message ID:
01386909
Vues:
84
>>>The decision as to which option to use should not be based on this relatively meaningless performance test but rather on which option provides you with the best functionality (and maintainability) for the job at hand.
>>
>>Rigth. Furthermore depending on what the job would do, what type of variables, results etc it is also possible that VFP is not the good choice for it. Saying needs fast processing of 1000 elements reminds me of scientific calculations which a link to an F# COM dll might be the best choice, gaining both speed and higher accuracy. Basically with 1000 elements I would say within VFP array would be faster. If it is something like splitting a words collection then neither array nor the cursor os the fastest thing in VFP but strangely a UI object - combobox.
>>Cetin
>
>Hi Cetin
>
>Hmm interesting. Plesa give us some more details here. I have task of such nature, so I am really interested :)
>
>TIA
>Sergio

Hi Srdjan,
(sometimes I am not sure if I should call you Srdjan or Sergio - both should be right:)
This sample would be very basic and hence easiser to understand then complex code IMHO. You can download F# 1.9.6.2 from:

http://www.microsoft.com/downloads/details.aspx?FamilyID=61ad6924-93ad-48dc-8c67-60f7e7803d3c&displaylang=en

It is cool IMHO, I try to use it besides C#. It has an interactive console, can be used from within VS as well. Anyway back to our sample:)

This code is a simple Calculator that returns the first N Fibonacci numbers - file FSharpCOM.fs:
#light
open System.Runtime.InteropServices
[<ProgId("cbFSharp.Demo")>]
[<ComVisible(true)>]
type Calculator() =
    let fibs =
        Seq.unfold
            (fun (n0, n1) ->
                Some(n0, (n1, n0 + n1)))
            (1,1)

    member x.firstN (x:int) = 
        Seq.take x fibs |> Seq.to_array
To create the COM and register you would do like this (output should be similar but not exact):
C:\temp>md FSharpCOM

C:\temp>cd FSharpCOM

C:\temp\FSharpCOM>notepad FSharpCOM.fs

C:\temp\FSharpCOM>sn -k cetin.snk

Microsoft (R) .NET Framework Strong Name Utility  Version 3.5.30729.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Key pair written to cetin.snk

C:\temp\FSharpCOM>"C:\Program Files\FSharp-1.9.6.2\bin\fsc.exe" -a --keyfile
cetin.snk FSharpCOM.fs
Microsoft F# Compiler, (c) Microsoft Corporation, All Rights Reserved
F# Version 1.9.6.2, compiling for .NET Framework Version v2.0.50727

C:\temp\FSharpCOM>dir
 Volume in drive C is XPBoot
 Volume Serial Number is A8FA-725C

 Directory of C:\temp\FSharpCOM

02/16/2009  06:39 PM    <DIR>          .
02/16/2009  06:39 PM    <DIR>          ..
02/16/2009  06:38 PM               596 cetin.snk
02/16/2009  06:39 PM             5,632 FSharpCOM.dll
02/16/2009  06:38 PM               345 FSharpCOM.fs
               3 File(s)          6,573 bytes
               2 Dir(s)  64,522,588,160 bytes free

C:\temp\FSharpCOM>regasm FSharpCOM.dll /codebase
Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.3053
Copyright (C) Microsoft Corporation 1998-2004.  All rights reserved.

Types registered successfully
And finally test code in VFP:
clear
o = Createobject('cbFSharp.Demo')
Local Array laFib[1]
laFib = o.FirstN(20)
For ix = 1 To 20
  ? laFib[m.ix]
Endfor
PS: Fibonacci code is not mine, got from Robert Pickering's "Foundations of F#" book. The books are available via safari.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform