Slow printing to console screen

New to FreeBASIC? Post your questions here.
Post Reply
fzabkar
Posts: 154
Joined: Sep 29, 2018 2:52
Location: Australia

Slow printing to console screen

Post by fzabkar »

I'm running Windows 10 on a 2.4GHz Core 2 Duo.

I'm finding that printing to the console screen is noticeably slow.

The following code illustrates this behaviour, at least on my old machine:

http://www.users.on.net/~fzabkar/temp/consprnt.bas
http://www.users.on.net/~fzabkar/temp/consprnt.exe

Is this a Windows "thing", or is it FB?

Code: Select all

Dim row as UByte
Dim col as UByte
Dim sRowData As String


For row = 1 To 50

    For col = 0 To 39

        Print Using "##"; col Mod 10;

    Next col

    Print

Next row

Print

Sleep



For row = 1 To 50

    For col = 0 To 39

        Print col Mod 10;

    Next col

    Print

Next row

Print

Sleep



For row = 1 To 50

    sRowData = ""

    For col = 0 To 39

        sRowData &= " " & Hex( col Mod 10, 1 )

    Next col

    Print sRowData

Next row

Print

Sleep



For row = 1 To 50

    Print " 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9"

Next row

Sleep
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Slow printing to console screen

Post by badidea »

fzabkar wrote:Is this a Windows "thing", or is it FB?
I always thought it was a linux thing: Extremely slow screen handling
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: Slow printing to console screen

Post by srvaldez »

@fzabkar
the perception of slow or fast is subjective, your test does not give a performance benchmark, say in milliseconds to completion
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: Slow printing to console screen

Post by srvaldez »

here's your test with timing

Code: Select all

' # include "vbcompat.bi"

Dim row as UByte
Dim col as UByte
Dim sRowData As String
dim as double t

t=timer
For row = 1 To 250
    
    For col = 0 To 39
        
        Print Using "##"; col Mod 10;
        
    Next col
    
    Print

Next row

Print timer-t

Sleep


t=timer
For row = 1 To 250
    
    For col = 0 To 39
        
        Print col Mod 10;
        
    Next col
    
    Print

Next row

Print timer-t

Sleep


t=timer
For row = 1 To 250
    
    sRowData = ""
    
    For col = 0 To 39
        
        sRowData &= " " & Hex( col Mod 10, 1 )
        
    Next col
    
    Print sRowData

Next row

Print timer-t

Sleep


t=timer
For row = 1 To 250
    
    Print " 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9"
    
Next row

Print timer-t
Sleep
times using the Windows cmd

Code: Select all

1.116
1.067
0.384
0.3265
times using conEmu https://sourceforge.net/projects/conemu/files/

Code: Select all

0.4929
0.4877
0.0493
0.0476
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Slow printing to console screen

Post by badidea »

My times on Ubuntu mate, mate terminal:
0.083...
0.037...
0.011...
0.0046...
fzabkar
Posts: 154
Joined: Sep 29, 2018 2:52
Location: Australia

Re: Slow printing to console screen

Post by fzabkar »

Thanks @srvaldez, I had already modified my code with timers, but here are my results using your mods (Windows 10 CMD on 2.4GHz Core 2 Duo):

7.90...
7.66...
0.616...
0.651...
Last edited by fzabkar on Sep 03, 2020 23:34, edited 1 time in total.
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: Slow printing to console screen

Post by srvaldez »

@fzabkar
what vesion of FB are you using and what command options if any are you using?
also, is your computer a laptop?
fzabkar
Posts: 154
Joined: Sep 29, 2018 2:52
Location: Australia

Re: Slow printing to console screen

Post by fzabkar »

srvaldez wrote:@fzabkar
what vesion of FB are you using and what command options if any are you using?
also, is your computer a laptop?
FB 1.07.1 for Win32

I'm using an IDE (FBIde 0.4) with a compiler command of ...

"<$fbc>" "<$file>"

.. so I guess that means there are no compiler options.

Computer is a desktop PC.
Motherboard is Gigabyte 945GCM-S2L
OS is Windows 10 Pro, 10.0.18363, 32-bit
4GB DRAM
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Slow printing to console screen

Post by jj2007 »

fzabkar wrote:Thanks @srvaldez, I had already modified my code with timers, but here are my results using your mods (Windows 10 CMD on 2.4GHz Core 2 Duo):

7.90...
7.66...
0.616...
0.651...
1.79, 1.72, 0.452, 0.454 here, notebook with a 8 year old Core i5
fzabkar
Posts: 154
Joined: Sep 29, 2018 2:52
Location: Australia

Re: Slow printing to console screen

Post by fzabkar »

I switched to the "legacy console" and was initially surprised at the 2x performance increase. Then I realised that the execution speed was dependent on the size of the CMD window. Smaller windows result in higher speeds.

Legacy console, small window, two consecutive runs

5.68
4.77
1.32
1.55

5.43
5.08
1.35
1.42

new console, full screen window, two consecutive runs

10.6
8.22
0.719
0.577

7.68
7.65
0.705
0.696


new console, small screen window, two consecutive runs

4.81
4.79
3.53 <-- not a typo ???
0.525

4.81
4.55
0.503
0.478

new console, alt-enter (full screen), single run

7.91
7.47
0.665
0.735

new console, window width shrunk to ~12 chars, two consecutive runs

3.45
3.40
0.947
0.973

4.17
3.98
0.892
0.990

new console, window width shrunk to ~12 chars, height shrunk to 3 lines, two consecutive runs

2.54
3.16
0.714
0.910

3.29
3.29
0.697
0.786
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: Slow printing to console screen

Post by srvaldez »

I also noticed speed differences depending on the console size
but your times are indeed very slow
fzabkar
Posts: 154
Joined: Sep 29, 2018 2:52
Location: Australia

Re: Slow printing to console screen

Post by fzabkar »

If I redirect the output to a file, at the command line, my results become ...

0.143...
0.111...
0.00751...
0.00367...

Doesn't this confirm that the problem is with Windows?

Is it possible that every Print statement results in a total screen rewrite, even when there is no scrolling? Could this explain why printing each column in a 40-column row increases the execution time by 10 times or more?
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Slow printing to console screen

Post by deltarho[1859] »

Just for fun - time 'Screen 19'.
fzabkar
Posts: 154
Joined: Sep 29, 2018 2:52
Location: Australia

Re: Slow printing to console screen

Post by fzabkar »

With Screen 19 (two consecutive passes) ...

0.166
0.0991
0.163
0.0361

0.144
0.247
0.174
0.102
fzabkar
Posts: 154
Joined: Sep 29, 2018 2:52
Location: Australia

Re: Slow printing to console screen

Post by fzabkar »

If my theory about total screen rewrites has any merit, then I wonder if the difference between my setup and others is that I'm using a VGA connection to my monitor rather than HDMI (because my onboard graphics doesn't have HDMI). Is there anyone who is getting good speeds via VGA?
Post Reply