Why is this lagging?

General FreeBASIC programming questions.
Post Reply
mrminecrafttnt
Posts: 131
Joined: Feb 11, 2013 12:23

Why is this lagging?

Post by mrminecrafttnt »

Code: Select all

dim shared as double lagtime,t1,t2,recordlagtime
screenres 640,480
locate ,,0
do
    t1 = timer
    locate 1,1
    print chr(int(rnd*255));
    t2 = timer
    lagtime = t2-t1
    if lagtime > recordlagtime then recordlagtime = lagtime
    locate 30,2
    print using "RECORDLAGTIME: ##.#####";recordlagtime;
    print "sec"
    
loop



vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Re: Why is this lagging?

Post by vdecampo »

Three issues I see,,,

#1. Running a tight loop without a Sleep can hog the CPU.
#2. Randomly you are printing the BELL character which blocks the console until the beep sound is finished playing
#3. IIRC the Timer only has an accuracy down to 15ms.

Cheers
-Vince
Post Reply