Re: slow startup on windows
Roland Hughes via Foxgui-users <[email protected]> Sat, 26 Oct 2024 18:33:58 -0500
| Newsgroups | gmane.comp.lib.fox-toolkit.user |
|---|---|
| Message-ID | <[email protected]> |
I'm shocked any of this ran. The compiler should have optimized it out.
On 10/26/2024 9:06 AM, John Selverian wrote:
> I put these loops into a different program I have that starts
> essentially instantly on both Windows and Linux. On both
> platforms these loops take about 7 seconds. Linux is running in a
> VM on the Windows machine.
>
> So I guess it not the allocation process.
>
> Any other ideas I should try?
>
>
>
> long num = 50000000;
> // long num = 50,000,000;
> {
> FXString* strs = new FXString[num];
> for (long i = 0; i < num; i++)
> {
> strs[i] = "test string";
> }
> delete[] strs;
> }
>
> {
> FXString* tmp;
> for (long i = 0; i < num; i++)
> {
> tmp = new FXString("test string");
> delete tmp;
> }
> }
>
>
>
> -----Original Message-----
> From: [email protected] <[email protected]>
> Sent: Friday, October 25, 2024 2:16 PM
> To: [email protected]
> Cc: [email protected]; 'Enno Rehling'
> <[email protected]>; [email protected]
> Subject: Re: [Foxgui-users] slow startup on windows
>
> On 2024-10-25 10:43, John Selverian wrote:
>> The program is a database where everything is stored as
> strings,
>> they're all wrapped in classes, so its actually stored as a 4D
> array
>> of classes. When it's running it takes 235 MB in memory.
>>
>> The strings are not displayed in the UI.
>>
>> I timed this:
>>
>> FXString* tmp;
>> long num = 500000;
>> //long num = 5000000;
>> for (long i = 0; i < num; i++)
>> {
>> tmp = new FXString("test string");
>> delete tmp;
>> }
>>
>> For num = 500,000 it's somewhere around 1 second, for num =
>> 5,000,000 takes about 3 seconds. I also used a longer string
> ("test
>> string test string test string test string test string test
> string
>> test string test string ") and saw no effect. I'm just timing
> in the
>> debugger with a stopwatch, nothing fancy so the times are only
>> approximate but clearly noticeable.
> Of course, it depends on your machine, but it seems entirely
> reasonable.
>
> Debug vs. release may make significant difference. Also, make
> sure target arch is set correctly [-with-arch=native optimizes
> for local machine, i.e. the one the compiler is running on].
>
> Your test is actually a-typical, you're actually doing 1,000,000
> and 10,000,000 allocations. for each i, you're allocating both
> the string and the string's buffer.
>
> Also, repeatedly allocating and freeing the same size entity will
> probably recycle memory, this is not the same as allocating NEW
> memory 500,000 times.
>
> A more fair test may be:
>
> FXString strs = new FXString [num];
> for (long i = 0; i < num; i++){
> strs[i]="test string";
> }
> delete [] strs;
>
> This will perform num+1 allocations, num for each string's
> buffer, and one giant one for the array-of-strings.
>
>
> FYI, time of a memory allocation is somewhat independent of the
> size being allocated. Somewhat, because once the size exceeds a
> certain value, the system will switch to an mmap call and do an
> operating system call; for the gory details, look in the file
> ~/glibc/malloc/malloc.c.
>
>
>
> -- JVZ
>
>
>
> _______________________________________________
> Foxgui-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/foxgui-users
--
Roland Hughes, President
Logikal Solutions
(630)-205-1593 (cell)
https://theminimumyouneedtoknow.com
https://infiniteexposure.net
https://johnsmith-book.com