FB Slow on ME

General FreeBASIC programming questions.
Post Reply
Theunis Jansen
Posts: 248
Joined: Jul 01, 2010 9:35

FB Slow on ME

Post by Theunis Jansen »

I am a bit puzzled. I compiled a QB program using #Lang "fblite" and when I ran it on ME it executed slower than when I ran the same program in ME using the QB 4.5 interpreter. Yes that is correct the interpreter is faster than the compiled program.
This was quite obvious when I draw a fancy frame using FOR...NEXT. The Screen I use is SCREEN 0.

Is there a way to Bsave the screen without having to save it to a BMP which is monstrous compared to the QB Bsave or my routine using block graphics to draw the screen. Or to speed up the execution?
Remember I am an ancient on pension so to solve the problem by upgrading to a new PC isn't really an option. (last year I was the oldest person on the forum)
I am using the most recent FB which I downloaded about 3-4 weeks ago. Using FBedit on the same PC it seems to run that tad faster than FBide, which also puzzles me.
RockTheSchock
Posts: 252
Joined: Mar 12, 2006 16:25

Re: FB Slow on ME

Post by RockTheSchock »

if you really need a bsave for console you can write your own. A while ago i have written a bload function. If i find some time later i will write the bsave function.
http://www.freebasic.net/forum/viewtopi ... 30#p184834

Here you find all information about console screen mode
http://www.freebasic-portal.de/befehlsr ... ad-59.html

But why do you need to bsave your screen? We could help you better if you post some code.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: FB Slow on ME

Post by MichaelW »

I think the problem is likely to be with the general slowness of the Windows console. If it is, then under ME you can probably work around it by compiling your program to a DOS executable. You can do this directly with FreeBASIC DOS, or indirectly by cross compiling to a DOS target with your Windows installation, if it is properly set up to do so. Mine is, and as I recall I:

Downloaded the FreeBASIC DOS zip archive for the same version as my Windows installation.

Extracted the files to a temporary directory.

Copied \bin\dos, \lib\dos, \examples\dos, and \inc\dos to the matching directories in my Windows installation (so for example the \bin directory in my Windows installation ended up with a \dos and a \win32 subdirectory).

*** See my post below for two additional components ***


Then to compile you just add a -target dos switch to the fbc command line.
Last edited by MichaelW on Apr 18, 2013 6:27, edited 1 time in total.
Theunis Jansen
Posts: 248
Joined: Jul 01, 2010 9:35

Re: FB Slow on ME

Post by Theunis Jansen »

@MichaelW
Thank you. I will give it a try.

@ShockTheRock
Thanks again for the prog to display BSV's.
It is not necessary to write a BSAVE.
I was just wondering if someone had not come across such a prog.
In the days of yore there were actually ways devised to load a PNG or BMP using QB.
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: FB Slow on ME

Post by counting_pine »

There are ways of loading images in FB but, as in QB, they would depend not on using the console but on a graphics mode (e.g. Screenres w,h or Screen 13)..
For what it's worth, I was using FB on Windows Me a few years ago without any speed problems. I wonder if maybe there's some software that's changing the way the console works, or something..
Does fullscreen/windowed make any difference?
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: FB Slow on ME

Post by dodicat »

This is a bit off topic, I apologize.

MichaelW wrote:

"I think the problem is likely to be with the general slowness of the Windows console"

I've been doing a bit of C++ comparisons to FreeBasic for execution speeds.
Win XP
I used a prime number generator.
Get a prime number and print it to the console.
At first I was disappointed with FreeBasic's lack of speed.
After a bit of head scratching I discovered the problem, The algorithm speed wasn't the isue, it was the printout speed.
Here's a simple demo comparing the C console (using crt.bi) and the Freebasic console.
Just toggle lines 32~33 to compare the printing speeds.
I should imagine bare printing to a file would also be affected, but I haven't tested this.

Code: Select all

#include "crt.bi"

Function isprime(n As Ulongint) As Integer
    If (n=2) Or (n=3) Then Return -1
    If n Mod 2=0 Then Exit Function
    If n Mod 3=0 Then Exit Function
    Dim As Ulongint limit=Sqr(N)+1
    For I As Ulongint=6 To limit Step 6
        If N Mod (i-1)=0 Then Exit Function
        If N Mod (i+1)=0 Then Exit Function
    Next I
    Return -1
End Function
'==========================================
dim as double t1,t2''timers
dim as string ans
dim as integer numprimes 'counter

t1=timer
for i as ulongint =292232721 to 292432721 step 2
    if isprime(i) then ans=ans+str(i)+chr(10):numprimes=numprimes+1
next i
t2=timer
var pt=t2-t1 'time to get the primes
sleep 10

'TWO METHODS TO PRINT RESULTS:
t1=timer

'CHOOSE ONE OF THE PRINTING OPTIONS THEN THE OTHER.
printf("%s",ans)
'print ans


t2=timer
print
print "Time for primes ";pt
print "time to print ";t2-t1
print "Number found ";numprimes
sleep

     
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: FB Slow on ME

Post by dodicat »

I've had a shot at Bsave, where the data saved is similar to the data printed to the console.
99 percent success. the first line is a bit iffy.
Use Wordpad to open the text file, notepad doesn't fetch new lines.
Seems the fourth parameter of Bsave could adjust the ouput format.
But I've skipped it here.

The help file isn't much use really, in my opinion. Especially to members like myself who need a clear explanation and a couple of examples to sink things in.

Code: Select all

#include "crt.bi"

screen 8
color ,3
print "Calculating primes"
Function isprime(n As Ulongint) As Integer
    If (n=2) Or (n=3) Then Return -1
    If n Mod 2=0 Then Exit Function
    If n Mod 3=0 Then Exit Function
    Dim As Ulongint limit=Sqr(N)+1
    For I As Ulongint=6 To limit Step 6
        If N Mod (i-1)=0 Then Exit Function
        If N Mod (i+1)=0 Then Exit Function
    Next I
    Return -1
End Function
'==========================================
dim as double t1,t2''timers
dim as string ans

dim as integer numprimes 

t1=timer
for i as ulongint =292232721 to 292432721 step 2
    if isprime(i) then
     ans=ans+str(i)+chr(10)
     numprimes=numprimes+1
     end if
next i
t2=timer
dim as double pt=t2-t1 'time to get the primes
sleep 10


t1=timer

'Quick print to console
printf("%s",ans)

t2=timer
print
print "Time for primes        ";pt
print "time to console print  ";t2-t1
print "Number of primes found ";numprimes
print
print "Bsaved to primestring.txt"
print
print "<ESC> to end"

dim as ubyte ptr AddressOfAnswer=@ans[0]


bsave("primestring.txt",AddressOfAnswer,len(ans))
sleep

      
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: FB Slow on ME

Post by MichaelW »

In the course of cross compiling dodicat’s print comparison code to a DOS app I discovered that I had missed two directories when I copied the FreeBASIC DOS components into my FreeBASIC Windows installation, inc\crt\dos and inc\crt\sys\dos.

My results, running on a 500MHz P3 under Windows XP:

Code: Select all

Windows app, time to print with Print:    21.1893332811851 seconds
Windows app, time to print with the CRT:  12.56005749334054 seconds
DOS app, time to print with Print:        0.3799998760223389 seconds
DOS app, time to print with the CRT:      1.039999961853027 seconds
I was guessing that running under NTVDM the print speed would be lower than it would be running under Windows 9x/ME, but perhaps not.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: FB Slow on ME

Post by dodicat »

I've got an old server with Win XP add dos 6 on a separate partition.
twin Pentium 3 @ 933 Mhz each.

Using fbdos.

For the prime code:
about 8 seconds to get the primes in ALL cases.

Under XP dos box
crt printf -- .49 secs.
PRINT -- .15 secs.

With pure dos 6
crt printf -- 24 seconds
PRINT -- 20 seconds.

Of course DOS 6 gives no Window, and using the XP dosbox with Alt + Enter (Full screen) gives over 40 seconds for either of the print methods with my flatscreen monitor, and half that(ish) with the old fashioned CRT monitor.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: FB Slow on ME

Post by MichaelW »

My (approximate) results, running on a 300MHz P2 under Windows ME:

Code: Select all

Windows app, time to print with Print:    2.134 seconds
Windows app, time to print with the CRT:  4.029 seconds
DOS app, time to print with Print:        0.390 seconds windowed, 15.430 fullscreen
DOS app, time to print with the CRT:      1.980 seconds windowed, 16.320 fullscreen
The time to find the primes was ~26 seconds for the Windows app and ~21 seconds for the DOS app.
Post Reply