LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Dictionary can't handle Longs 10,000,000?

I was writing a program that took surprisingly long. I started
commenting things out to figure out what was taking so long, and the
very last thing i checked - the very last thing i would have thought
would take so long - was it. The dictionary object. I was using keys
of type Long like 19980512, and it was taking forever. So, I did a test
to see why. I could have sworn longs were always an OK choice for keys
in the past. I played around with it until i came to the magic number
of 10,000,000. Any Long above this number takes 220 times longer to add
to the dictionary than a Long below.

Does anyone have any idea why? Poor hashing function? Bug?





Sub DictionaryTesting()
Dim i As Long, dic As New Scripting.Dictionary
Dim myTimer As New clsTimer


myTimer.StartTimer
For i = 1 To 10000
dic.Add i + 10000001#, i - 1
Next i

myTimer.StopTimer
Debug.Print "Long, 10,000,000", myTimer.PerformanceString

Set dic = Nothing


myTimer.StartTimer
For i = 1 To 10000
dic.Add i + 9989999#, i - 1
Next i

myTimer.StopTimer
Debug.Print "Long, < 10,000,000", myTimer.PerformanceString

Set dic = Nothing



myTimer.StartTimer
For i = 1 To 10000
dic.Add CDbl(i + 9990999#), i - 1
Next i

myTimer.StopTimer
Debug.Print "Double", myTimer.PerformanceString

Set dic = Nothing



myTimer.StartTimer
For i = 1 To 10000
dic.Add CVar(i + 9990999#), i - 1
Next i

myTimer.StopTimer
Debug.Print "Variant", myTimer.PerformanceString

Set dic = Nothing



myTimer.StartTimer
For i = 1 To 10000
dic.Add CSng(i + 9990999#), i - 1
Next i

myTimer.StopTimer
Debug.Print "Single", myTimer.PerformanceString

Set dic = Nothing



myTimer.StartTimer
For i = 1 To 10000
dic.Add CStr(i + 19990101), i - 1
Next i

myTimer.StopTimer
Debug.Print "String", myTimer.PerformanceString

End Sub

























--------------------------------------
clsTimer
--------------------------------------

'Private Declare Function timeBeginPeriod Lib "winmm.dll" (ByVal uPeriod
As Long) As Long
'Private Declare Function timeEndPeriod Lib "winmm.dll" (ByVal uPeriod
As Long) As Long

Private Declare Function timeGetTime Lib "winmm.dll" () As Long


' Properties.
Private m_lngBeginTime As Long
Private m_lngEndTime As Long

Private m_blnRunning As Boolean


'################################################# #########################
' Read properties.
'################################################# #########################

Public Property Get BeginTime() As Long
BeginTime = m_lngBeginTime
End Property

Public Property Get EndTime() As Long
EndTime = m_lngEndTime
End Property

Public Property Get Running() As Boolean
Running = m_blnRunning
End Property

'################################################# #########################
' Write properties.
'################################################# #########################



'################################################# #########################
' Methods.
'################################################# #########################


Public Sub StartTimer()
m_blnRunning = True
m_lngBeginTime = timeGetTime()
End Sub

Public Sub StopTimer()
m_lngEndTime = timeGetTime()
m_blnRunning = False
End Sub


Public Function PerformanceString() As String
PerformanceString = SecondsElapsed() & " seconds elapsed."
End Function

Public Function TimeElapsed() As Long
If m_blnRunning Then
TimeElapsed = timeGetTime() - m_lngBeginTime
Else
TimeElapsed = m_lngEndTime - m_lngBeginTime
End If

End Function

Public Function SecondsElapsed() As Double
If m_blnRunning Then
SecondsElapsed = (timeGetTime() - m_lngBeginTime) / 1000
Else
SecondsElapsed = (m_lngEndTime - m_lngBeginTime) / 1000
End If

End Function


















 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fill handle turned into a move handle Northwoods Excel Discussion (Misc queries) 1 March 2nd 07 03:40 PM
Convert Lats and longs to decimals dharmik Excel Worksheet Functions 2 March 30th 06 07:48 PM
convert lats and longs to decimals dharmik Excel Worksheet Functions 1 March 28th 06 07:12 PM
dictionary Libby Excel Programming 0 November 15th 04 12:53 PM
Longs losing accuracy pikus Excel Programming 2 December 22nd 03 10:22 PM


All times are GMT +1. The time now is 04:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"