I did a test, changing from nro_original.ToText(locale) to Format(nro_original,cadena_formato), part of the code:
For i = 1 To 1419818
nro_original = i
texto = nro_original.ToText(locale)
'texto = Format(nro_original,cadena_formato)
Next i
Using format I get 650 ticks difference.
Using .ToText(locale) I get 247 ticks difference.
I didn’t use a function, maybe will test that too.
Calling GetCurrencyFormatEx directly should be quicker than going via the framework as you would be able to re-use certain things that the framework would need to initialise for every call such as the CURRENCYFMT structure and the the buffer which receives the output.
roman: i am doing a stress test with a listbox that has 300.000 rows and 5 numeric columns. my final goal is to populate the listbox faster as possible
If you have a lot of data like this, you usually only work on the data that is currently shown to the user, maybe 100 rows. There’s not much point formatting all the other data if the user never actually sees it.
I’m going to think outside of the box here. The best way to reduce the overhead may be to do the work ahead of time. Add a column to the database and store a copy of the currency field as a pre-formatted string. When milliseconds count and you’re displaying 300K records, this might be the way to speed up the initial hit.
If I was designing a program populating 300,000 rows, I would not do it all in one method.
I would probably populate like 5 or ten pages, which can be done fairly fast, and then use a timer to populate the rest of the rows. For the user, the update will be immediate or so, he will even be able to scroll down a bit, but the completion will take somewhat longer. Since it is done in a timer, the UI will not be frozen, and it should pretty much transparent to the user.
If youre putting values in a listbox then I would put them in the celltag and only implement celltextpaint to draw the number formatted as you want - that way you only do this for the cells in the listbox that are visible and not every row. That could cut down the number of times you need to do this by a lot.
There are several benefits connected to this:
You can fill the listbox much faster. Instead of calculating strings for each row, filling the listbox is just a combination of empty AddRows and AddRowTags (or AddCellTags).
You have almost full flexibility about the design of your cell: multiple lines, images, fonts and sizes can be created on the fly in the draw events.
This is almost as good as having direct access to the DataSource object.