Sign in to follow this  
Followers 0
littleclown

search in array for number bigger than X

6 posts in this topic

#1 ·  Posted (edited)

Hello. I need to search from the beginning in the huge ($ar[1000000]) array for string bigger than X, then write down the position and continue search for number bigger than X.

In final I should have list with all positions on numbers bigger than X.

I need to use an array functions for this because if i create a loop for all one million numbers I will have a huge delay (as far I can see array-oriented commands are really faster than everything else)

Thank you in advance.

If there is something like _ArrayFindAll but with > < options will be great.

Edited by littleclown

Share this post


Link to post
Share on other sites



littleclown,

if i create a loop for all one million numbers I will have a huge delay (as far I can see array-oriented commands are really faster than everything else)

If you look inside Array.au3, you will see that _ArrayFindAll calls _ArraySearch which (horror :D !) uses a loop (For $i = $iStart To $iEnd)! :D

In fact _Array* functions are usually pretty slow - particularly those which involve changing the size of the array. :D

So I would just use a loop and accept that anything involving an array of that size is going to take a while to run. :(

M23

P.S. How on earth do you initialise the array? From where do you get the data? And what are you trying to do with it? :graduated:


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hello littleclown,

I never had speed issues with searching through an array with my own custom loops. But again, I never dealt with arrays this large. So I created a little test to see for myself. I buillt a loop to create the array assiging a random number between 0 and 99 to each index. Then initiated a timer for my search loop, then called the time difference after the the loop had finished and found that it found all indexes over 95 in less than 5 seconds. However the _ArrayDisplay() took almost a minute to load up. So if your experiencing large load times, it may have to do with your display method.

Here is my example if you would like to time it yourself:

#include <Array.au3>

Local $x = 95

Local $ar[1000000]
$timer1 = TimerInit()
For $r = 0 To UBound($ar)-1
    $ar[$r] = Random(0,99,1)
Next
$diff1 = _GetDiff($timer1)

$timer2 = TimerInit()
Local $indexes
For $i = 0 To UBound($ar)-1
    If $ar[$i] > $x Then $indexes &= $i & ','
Next
$indexes = StringTrimRight($indexes,1)
$diff2 = _GetDiff($timer2)

$index_Array = StringSplit($indexes,',')
_ArrayDisplay($index_Array,'Index Points')

MsgBox(0,'Times','Time to populate Array: ' & $diff1 & @CRLF & 'Time to Search Array; ' & $diff2)

_ArrayDisplay($ar,'Array view')

Func _GetDiff($timer)
    Local $timeDiff = TimerDiff($timer), $hr, $min, $sec, $ms
    If $timeDiff < 1000 Then
        Return (Round($timeDiff) & ' milliseconds' )
    ElseIf $timeDiff < 60000 Then
        $sec = Floor($timeDiff/1000)
        $ms = Round($timeDiff - ($sec * 1000))
        Return ($sec & '.' & $ms & ' seconds')
    ElseIf $timeDiff < 3600000 Then
        $min = Floor($timeDiff/60000)
        $sec = Floor(($timeDiff - ($min * 60000))/1000)
        $ms = Round($timeDiff - ($sec * 1000) - ($min * 60000))
        Return ($min & ':' & $sec & '.' & $ms & ' minutes')
    ElseIf $timeDiff>= 3600000 Then
        $hr = Floor($timeDiff/3600000)
        $min = Floor(($timeDiff-($hr * 3600000))/60000)
        $sec = Floor(($timeDiff - ($min * 60000)-($hr * 3600000))/1000)
        $ms = Round($timeDiff - ($sec * 1000) - ($min * 60000)-($hr * 3600000))
        Return ($hr & ':' & $min & ':' & $sec & '.' & $ms & ' hours')
    EndIf
    Return SetError(1,0,0)
EndFunc

Realm


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Let me check something. I use consolewrite - maybe the issue is there.

Actually I try to analize wav file but on really low level (I know about bass, but i prefer to write it to my own). This is only 10 second wav file in a array :graduated:.

EDIT: 20 seconds! Thanks guys - maybe I just need somebody to think with me sometimes :(.

I did not initialization issues, but can I be sure there will be no issues everywhere? I will distribute exe if it works.

Edited by littleclown

Share this post


Link to post
Share on other sites

Let me check something. I use consolewrite - maybe the issue is there.

Actually I try to analize wav file but on really low level (I know about bass, but i prefer to write it to my own). This is only 10 second wav file in a array :graduated:.

EDIT: 20 seconds! Thanks guys - maybe I just need somebody to think with me sometimes :(.

I did not initialization issues, but can I be sure there will be no issues everywhere? I will distribute exe if it works.

The only way to be sure there are no issues is to include Opt("BugFreeMode",1) in your code. And whether the exe is useful depends entirely on what it does :D


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

I just need to run it under 32 and 64 bit XP, Vista and windows 7.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0