Computing.Net > Forums > Programming > (q)basic programming

(q)basic programming

Reply to Message Icon

Original Message
Name: a girl
Date: April 8, 2002 at 23:31:43 Pacific
Subject: (q)basic programming
Comment:

I made a little program in qbasic but running it gives slower results than i hoped. My question is: are there oher basic programs that can run my program, maybe with a little adaptation?
thanks for any replies.


Report Offensive Message For Removal


Response Number 1
Name: A Certain TH
Date: April 9, 2002 at 01:15:57 Pacific
Subject: (q)basic programming
Reply: (edit)

Almost certainly. What does the program do?


Report Offensive Follow Up For Removal

Response Number 2
Name: a girl
Date: April 9, 2002 at 01:48:03 Pacific
Subject: (q)basic programming
Reply: (edit)

I give in some values, after which the computer has to search for a best result with it which it remembers and start again looking for a beter one. It uses mainly trial and error procedure (rnd: if 0 do this, if 1 do that eg).
hope this gives better insight.


Report Offensive Follow Up For Removal

Response Number 3
Name: A Certain TH
Date: April 9, 2002 at 02:40:14 Pacific
Subject: (q)basic programming
Reply: (edit)

I do apologise, and wouldn't normally have a go at someone for their language skills, but I really can't work out what you mean.

Can you paste the program in that you've written? [Replace greater-than and less-than symbols with ) and ( signs or they won't show up.]

Tom


Report Offensive Follow Up For Removal

Response Number 4
Name: Macke
Date: April 9, 2002 at 03:40:10 Pacific
Subject: (q)basic programming
Reply: (edit)

Use Dark Basic at darkbasic.com


Report Offensive Follow Up For Removal

Response Number 5
Name: a girl
Date: April 9, 2002 at 12:04:45 Pacific
Subject: (q)basic programming
Reply: (edit)

sorry for the language, think i was trying to give too much info on too little space there.
i think it might be a little bit too long for pasting it here, but the idea is like this:

time=time+10
computer chooses number: 0 or 1
if number is 0 then a=a+1 else it is a=a+2
loop this thing until a=100
if a=100 then give me the time

the program consists of a lot of these things, although a bit more complicated.
and don't embarass me this time with my language skills (I'm not english sorry)

i'll take a look at dark basic too.
thanks for the replies.


Report Offensive Follow Up For Removal


Response Number 6
Name: Jim
Date: April 10, 2002 at 01:49:20 Pacific
Subject: (q)basic programming
Reply: (edit)

What will happen if a is 99, and the computer chooses 1? Will a become 101, and skip the check for 100? Unless your code really had a hidden greater than sign in there, and the message board formatted it out. Maybe you should put one in.

Depending on your hardware, qbasic should run that program in less than 1 second. The problem may be in the program and not in the compiler.


Report Offensive Follow Up For Removal

Response Number 7
Name: a girl
Date: April 10, 2002 at 03:38:49 Pacific
Subject: (q)basic programming
Reply: (edit)

i hoped it would be obvious this wasn't what is used in the program, only a simplified version of it, and yes, in stripping it down to this example i obviously overlooked the point you made.
my program consists of: a lot of these things, of which i tried to give an example, they are often interacting, and are each in itself more complicated than that.
explained different: take something like the example above, make it more complicated, and add a lot of these together.
thats it
now what surprises me is that you say that it should take less than a second for that program. that already sounds long to me.
suppose i wanted the program to run 10000 times, 0.1 sec per turn (obviously less than a sec, but i really don't know nothing about computing times), then it would take 1000 seconds to finish. And that is my initial question: qbasic seems to run too slow for me, maybe there's something better that looks like it.


Report Offensive Follow Up For Removal

Response Number 8
Name: Jim
Date: April 10, 2002 at 11:56:28 Pacific
Subject: (q)basic programming
Reply: (edit)

Which version of qbasic are you using? Is it compiling your code or interpreting it? The version I have is an old verion, and it interprets the code, and yes it is very slow. Pretty much ANY compiler is going to be faster than an interpreter.

You're right, one second for that sample code is very long. I guess I was under the mistaken impression that your program was that simple, and couldn't figure out why it was taking so long.

I reccomend you do a web search on "BASIC compiler". You'll get more hits than you can shake a stick at. Some are free, some aren't. I don't know how many of them will be code compatible with qbasic, but it shouldn't be too hard to make it work.

If you want one to start with, try RapidQ. It's a free download, and self contained with no installation garbage to clutter up your computer. There is a GUI interface if you want to build gui apps, but for this one I expect you'll just want to use the RC.EXE compiler to make a console app.


Report Offensive Follow Up For Removal

Response Number 9
Name: A Certain TH
Date: April 11, 2002 at 06:23:10 Pacific
Subject: (q)basic programming
Reply: (edit)

Right. Maybe I should allow for the fact that you may not have understood my apology. (You could equally say to me that I am stupid for not understanding you)

Now we've got that out of the way, the situation stands. you are asking for help and people here can provide that help. But you need to help us to help you. If you can show us snippets of your code, then we may be able to show you improvements.

I know that the above example is a bare-bones version of your program, but even giving it extra tasks to do at various intervals, my first attempt made it run in 0.6746 seconds. And thats using VBA within Word on a pre-pentium PC, on a crap network. Which isn't the quickest environment.

We need to see things like:

"computer chooses number: 0 or 1" - is this random, or criterial?

"a = a + 1 or a = a + 2" - is 'a' just a variable which is incrementing? Or is it that you have 2 functions, and it depends on the previous criteria as to whether you run one or both? (or the same one twice?)

The things which you have omitted to tell us are the exact things which cost your processor time. And since you are trying to save time, I think they're the bits you should be telling us about!

And again: APOLOGIES if you think my tone is harsh. If English is your second language, then I think you have an amazing grasp of it. You are worth your weight in gold.

(Unless you're Bella Emberg)

Tom


Report Offensive Follow Up For Removal

Response Number 10
Name: a girl
Date: April 11, 2002 at 08:34:06 Pacific
Subject: (q)basic programming
Reply: (edit)

Thanks for all the comments I got so far.
I downloaded rapidq and tried to paste the program, but I seem to have to change something in the first line of my program. I still have to do that. Unfortunately, I read on the website that it was a bit less fast on computation site (the things like a=a+1). I just tried to look at the site and look up what they just said but they changed it and I can't find it back.
As for darkbasic, the only changing i needed to make is adding : after line number. But on running it seems even slower than qbasic. I just hope i did everything right. (note: I copied qbasic from my win98 cd. I know nothing about the version.)
As for the program itself, I pasted a piece here. The goto's are in itself referring to other pieces like this, also with goto's and other variables. The variables are always incrementing (or decrementing) or set back to its original value. With 'computer chooses 0 or 1' in the above example I meant random, as is mostly the case in the program, except for some times where a forced choice is made.
I hope this snippet as you call it clarifies it all.

120
f = 0
w = 0
FOR i = 1 TO (vl - y)
IF ah < 3 THEN GOTO 101
IF af < 11 THEN GOTO 104
IF m = 0 THEN GOTO 105
IF s = 0 THEN GOTO 106
125
RANDOMIZE TIMER
q = INT(RND * 5)
IF q = 0 THEN GOTO 213
127
wd = wd + 10
w = w + 1

130
NEXT i
PRINT "f:"; f;
PRINT "w:"; w;

It's all basically as simple as that to compute. Nevertheless, I have too little patience with it to let it run to get the desired results. I thought my computer would run it 10000 times in no time (btw I have a pentium 700 with 256MB memory ), but I seem to have overestimated that. :-(


Report Offensive Follow Up For Removal

Response Number 11
Name: Jim
Date: April 11, 2002 at 10:04:47 Pacific
Subject: (q)basic programming
Reply: (edit)

As I recall from my university days, some methods will speed up your program more than others. In order of effectiveness (in most cases):

1) Find a new faster algorithm if possible
2) Use a different language/compiler
3) Optimize the code

Your algorithms look to be pretty complex. If you want to spend the time to do some analysis of them you might be able to combine some of the operations or something to make it faster.

Basic isn't an inherently slow language. Although all interpreters and some compilers are. And some programming practices are. For example, floating point calculations take many times longer to do than integer calculations. If you don't declare f, w, i, and q as integers in your snippet, even the statements like w = w + 1 are going to be way slow. In any case, I think you're on the right track looking for another basic compiler. Or if you don't mind translating to another language, Turbo Pascal version 3.01A would be ideal for this program. Although it's 17 years old, for compile speed it's hard to beat, and it makes pretty efficient code.

If you want to optimize your code, there are several things that are evident. First, make sure all your integers are declared as integers so they aren't doing floating point calculations when they don't need to. Randoms also take a long time, so you might be able to optimize that some, and you probably don't need to reset the random seed every time you get a random number. Then look at things that are done in a loop. For example your for loop. It has to do the (vl - y) calculation and then check it against i in every iteration. If doing the loop backwards won't screw up your calculations, it would be more efficient. If you do for i = (vl - y) downto 1, it only has to do the (vl - y) calculation once, before it enters the loop, and then it just checks i against 1 in the iteration.


Report Offensive Follow Up For Removal

Response Number 12
Name: a girl
Date: April 11, 2002 at 10:55:58 Pacific
Subject: (q)basic programming
Reply: (edit)

Those tips are useful indeed.
I found what I wanted to quote on rapid basic on their site. It reads:
"1.1 How slow is Rapid-Q anyway?
Although Rapid-Q is based on compiling your sources to byte-code, execution isn't as slow as many think. Your programs will obviously slow down if you require heavy computation or to perform very low level manipulation to data. For example, reading a single byte from a 1MB file will take longer in Rapid-Q than in most languages, but not so extremely slow that you'll be sleeping at the keyboard. Same with looping I = I + 1 a few thousand times."

But I'll might give it a try if I find no other one (...tomorrow).


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: (q)basic programming

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge