[Gambas-user] Feature request: Array.Frequency
Emil Lenngren
emil.lenngren at ...626...
Sun May 18 16:10:12 CEST 2014
Yes, Variant is slower than other native data types, as it must always
examine the type of the variable when it is used.
Note that you should write "avValues As Variant" instead of Variant[],
since a Variant can contain any type (for example any Array). A Variant[]
however is always an array containing Variants, which might not be what you
want.
The JIT compiler is good at optimizing code that uses native datatypes, but
not so good at optimizing code that uses Variants.
If you want fast code that works on Integer arrays, you should have a
function that only accept Integer arrays.
2014-05-18 16:04 GMT+02:00 Patrik Karlsson <pata.karlsson at ...626...>:
> Ok, so the module looks like this now, is Variant slower than other native
> data types?
>
> Export
> Fast
>
> Public Function Frequency(avValues As Variant[], vValue As Variant) As
> Integer
>
> Dim i As Integer
> Dim iFrequency As Integer
>
> For i = 0 To avValues.Length - 1
> If avValues[i] = vValue Then
> Inc iFrequency
> Endif
> Next
>
> Return iFrequency
>
> End
>
>
>
> 2014-05-18 14:50 GMT+02:00 Emil Lenngren <emil.lenngren at ...626...>:
>
> > For best performance, loop over index from 0 to length-1 instead of using
> > the For Each construct.
> >
> >
> > 2014-05-18 14:43 GMT+02:00 Benoît Minisini <gambas at ...1...
> >:
> >
> > > Le 18/05/2014 13:44, Patrik Karlsson a écrit :
> > > > I'm converting a Java app of mine to Gambas and I could not find any
> > > > equivalent to Java's Collections.frequency [1].
> > > >
> > > > So I wrote this function for Integer[]:
> > > >
> > > > Private Function Frequency(aArray As Integer[], iValue As Integer) As
> > > > Integer
> > > >
> > > > Dim iCount As Integer
> > > > Dim iItem As Integer
> > > >
> > > > For Each iItem In aArray
> > > > If iItem = iValue Then
> > > > Inc iCount
> > > > Endif
> > > > Next
> > > >
> > > > Return iCount
> > > >
> > > > End
> > > >
> > > > Would it be possible to add Frequency as a read only property to
> > > gb.Array?
> > > >
> > > > /Patrik
> > > >
> > >
> > > Why don't you do that in Gambas using JIT compiler ?
> > >
> > > --
> > > Benoît Minisini
> > >
> > >
> > >
> >
> ------------------------------------------------------------------------------
> > > "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
> > > Instantly run your Selenium tests across 300+ browser/OS combos.
> > > Get unparalleled scalability from the best Selenium testing platform
> > > available
> > > Simple to use. Nothing to install. Get started now for free."
> > > http://p.sf.net/sfu/SauceLabs
> > > _______________________________________________
> > > Gambas-user mailing list
> > > Gambas-user at lists.sourceforge.net
> > > https://lists.sourceforge.net/lists/listinfo/gambas-user
> > >
> >
> >
> ------------------------------------------------------------------------------
> > "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
> > Instantly run your Selenium tests across 300+ browser/OS combos.
> > Get unparalleled scalability from the best Selenium testing platform
> > available
> > Simple to use. Nothing to install. Get started now for free."
> > http://p.sf.net/sfu/SauceLabs
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
>
> ------------------------------------------------------------------------------
> "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
> Instantly run your Selenium tests across 300+ browser/OS combos.
> Get unparalleled scalability from the best Selenium testing platform
> available
> Simple to use. Nothing to install. Get started now for free."
> http://p.sf.net/sfu/SauceLabs
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
More information about the User
mailing list