473,404 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

cdate is slow... any alternatives?

In implementing the IComparer method of a listview, I found sorts by date are incredibly slow. I used a second dummy project to find out what the issue was. Code as follows simply converts two strings to two dates, and if they are not dates, uses 1/1/1900. If str1, and str2 are both valid dates, this loop runs in milliseconds. If one is not a date, the loop funds in 8 seconds. If both are not dates, then the loop runs in 16 seconds!!
Can anyone suggest a way to speed this up? I understand that type conversion can be intensive, but this is ridiculous in my opinion..

[code snippet
On Error Resume Next
For intCounter = 1 To 100
dte1 = #1/1/1900
dte2 = #1/1/1900
dte1 = CDate(str1
dte2 = CDate(str2
[Date].Compare(dte1, dte2
Nex
[end code snippet]
Nov 20 '05 #1
5 1905
On Wed, 25 Feb 2004 07:31:08 -0800, "Eric Fleet"
<an*******@discussions.microsoft.com> wrote:
In implementing the IComparer method of a listview, I found sorts by date are incredibly slow. I used a second dummy project to find out what the issue was. Code as follows simply converts two strings to two dates, and if they are not dates, uses 1/1/1900. If str1, and str2 are both valid dates, this loop runs in milliseconds. If one is not a date, the loop funds in 8 seconds. If both are not dates, then the loop runs in 16 seconds!!!
Can anyone suggest a way to speed this up? I understand that type conversion can be intensive, but this is ridiculous in my opinion...

[code snippet]
On Error Resume Next
For intCounter = 1 To 1000
dte1 = #1/1/1900#
dte2 = #1/1/1900#
dte1 = CDate(str1)
dte2 = CDate(str2)
[Date].Compare(dte1, dte2)
Next
[end code snippet]


Have you tried using the DateTime class?
Try using DateTime.Parse() to parse the date..

What I ended up doing was using the date format "YYYY-MM-DD HH:MM:SS",
which is how SQL server likes to format dates. The nice thing about
it is that it will sort correctly if you use a regular string
comparison.

// CHRIS

Nov 20 '05 #2
I played around a bit, and found this 'solution'. I search the string for a "/" character before trying to cdate it. It gets rid of nearly all of the non-dates before I use cdate to convert. In my mind, the fact that this works says that microsoft's function is less than optimal. I would think it would kick out anything that is obviously not a date very quickly. For those curious, here is the new code snippet

For intCounter = 1 To 100000
On Error Resume Nex
dte1 = #1/1/1900
dte2 = #1/1/1900

If InStr(str1, "/", CompareMethod.Text) > 1 The
dte1 = CDate(str1
End I

If InStr(str2, "/", CompareMethod.Text) > 1 The
dte2 = CDate(str2
End I

[Date].Compare(dte1, dte2
Nex

Note that I increased the loop by a factor of 1,000, and it now takes 1.1 seconds regardless of whether str1 is not a date, str2 is not a date, or both. Without the 'pre-check', this would have about 4 hours and 15 minutes :

Eric
Nov 20 '05 #3
* "=?Utf-8?B?RXJpYyBGbGVldA==?=" <an*******@discussions.microsoft.com> scripsit:
In implementing the IComparer method of a listview, I found sorts by
date are incredibly slow.


Did you try 'DateTime.Parse'/'DateTime.ParseExcact'?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet/>
Nov 20 '05 #4
Thanks to you and Chris for your help. I was not aware of these functions... wasn't in the "See Also" for cdate. This is considerably faster than cdate, most likely due to its more specialized nature. It also avoids my weird code :

Thanks
Eric
Nov 20 '05 #5
* "=?Utf-8?B?RXJpYyBGbGVldA==?=" <an*******@discussions.microsoft.com> scripsit:
Thanks to you and Chris for your help. I was not aware of these
functions... wasn't in the "See Also" for cdate.


Always have a look at the datatype's methods!

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet/>
Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: Steven T. Hatton | last post by:
Now that I have a better grasp of the scope and capabilities of the C++ Standard Library, I understand that products such as Qt actually provide much of the same functionality through their own...
2
by: Yonatan Goraly | last post by:
I am in the process of adding PostgreSQL support for an application, in addition to Oracle and MS SQL. I am using PostgreSQL version 7.3.2, Red Hat 9.0 on Intel Pentium III board. I have a...
2
by: John M | last post by:
Hi, In my database I am converting grades into scores (A=7, B=6, B/C = 6.5) I'm told this is quite slow, and sure enough, a report doing a fair bit of this is slow. I used to have the...
1
by: IkyL234 | last post by:
I'm using Access2000. I have just designed a database which seems to be operating very slow on a network. There are currently only a few records in it. Should I be compacting it now before it gets...
6
by: Owen | last post by:
It doesnt seem to always pick up the sysem date format properly, for example if I do CDate("19/07/2005") it seems to return an error, even though my Regional Settigns are dd/MM/yyyy. It seems to...
52
by: frankgerlach | last post by:
>From my simple performance tests of SOAP it seems that it is about ten times slower than binary object request protocols such as RMI, IIOP or SimpleORB. Is this also YOUR experience ?
0
by: zamba | last post by:
hi im new with xsl and i have to process a xsl with a lot of xml (about 50.000) the transform is slow ..and i want to optimize my xsl . here is the example so if anybody could give some advices to...
8
by: chopin | last post by:
My goal is to take a date such as 1/1/2010 and convert it to 1/2010 or 1/10, either or. The way I am doing this is by using the format function as follows: Format(.,"mm/yyyy") The problem is...
1
by: mehaa | last post by:
Hi all, I am a novice with access programming.And just started to learn. I have a question similar to one of the posts in this forum. I have a semester field that shoudl have input data in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.