PDA

Click to See Complete Forum and Search --> : [Trial]Contest 1 - VB (.NET & Legacy) - Prime Numbers


Pages : [1] 2

Pino
Sep 8th, 2004, 02:11 PM
Contest 1 - Prime Numbers
Please Note This Is A Trial Contest And Is A Basic Example :)

Before starting I recommend you take a look at the Faq located here (http://vbforums.com/showthread.php?s=&threadid=303266)

Language

VB (Legacy) and VB .NET (entries from the two languages will be judged seperatly)

Deadline

25\09\04 (25th September 2004) Noon (1200 Hours) (GMT) I will not accept entries after this date

After I\We have finished marking we will show you how I\we marked the entries and the scores each application recieved.

Main Aims

The aim of this contest is to design a program which generates the first 1000 prime numbers and displays them in a standard VB listbox. (Please note that 1 is excluded from being a prime number!). Please be aware that we only want one prime number per item in the listbox, So code like lstPrimes.AddItem Prime1 & " - " & Prime2 & " - " & ... will not be accepted. This is mainly to keep the contest fair and also to allow us to test the listbox is correct item by item instead of doing extra processing.

What Is A Prime Number?

'Any integer greater than 1 that is divisible only by 1 and itself'

How Is It To Be Marked?

Firstly I will make sure your code actually generates the first 1000 prime numbers and displays them into a standard VB listbox if it does not, it will be disqualified from the contest!

Primarily the application you submit will be tested on its speed (On my computer) to generate the first 1000 prime numbers and display them into a listbox!

If 2 sets of code run at the same speed then it will be down to the best designed code (Me and the moderator team will take a look) If no winner is decided from this the 2 contestents will take joint-1st place

What If My Code Has Problems?

If there are any compile errors with your code or it simply does not work, it will not be accepted into the contest (simply because I dont have the time to debug code as well as mark entries)

3rd Party Controls

We see no need for 3rd party controls to be used in this contest, if you find a reason why you would need one please PM me or one of the Admin team

What Do I Win?

The prize for first place is a custom name title for the period of 2 weeks so you can show your fellow VBForum members you have wona contest!

Where Do I Send My Work?

You just reply to the thread located here (waiting for mod to accept)

What Format Should My Work Be In?
It would be best if you could zip up your project using winzip or another similar program!

Source code only please i cannot accept exe's or any form of compiled code!

Final Note

Have fun please remember the aims of the contests are to have fun, also please note commented code is not required but prefered!

MartinLiss
Sep 8th, 2004, 06:39 PM
Pino, didn't you mjean the first 1000 primes rather than the primes up to 1000?

NoteMe
Sep 8th, 2004, 06:49 PM
Am I supposed to see Martys post now....wasn't it supposed to be invisible? I though it should. If not...then everyone can steal code....:eek:

manavo11
Sep 8th, 2004, 06:56 PM
Maybe the attachments are invisible?

Danial
Sep 8th, 2004, 07:41 PM
Originally posted by NoteMe
Am I supposed to see Martys post now....wasn't it supposed to be invisible? I though it should. If not...then everyone can steal code....:eek:

I think only the posts made in the sub forum will be invisible, not this one.

Electroman
Sep 8th, 2004, 07:51 PM
Posted by Danial
I think only the posts made in the sub forum will be invisible, not this one. Thats the one, trust NoteMe to get confussed :D

I hadn't realised the forum was public now, has it been for long or just today?

MartinLiss
Sep 8th, 2004, 07:54 PM
Originally posted by Electroman
Thats the one, trust NoteMe to get confussed :D

I hadn't realised the forum was public now, has it been for long or just today? Brad made the change today.

wossname
Sep 9th, 2004, 02:40 PM
1. Are we allowed to provide out own timing statistics (assuming we agree to have the method of which scrutinised)? This enables us to more accurately show you how fast our algorithms are.

2. My algorithm requires me to specify the first 2 primes (2 and 3) in order for the algorithm to work, is this legal and / or will i be required to generate 2 more primes to compensate?

Please reply promptly.

I'm taking this seriously :D Hope you guys have a strong alg, cos I have.

Plus, do we get points for originality and sexiness of coding technique?

brad jones
Sep 9th, 2004, 02:43 PM
My assumption is that if it isn't in the rules, then it is fair :D

I'm also assuming there *will* be points for sexiness of code and such.

Pino and Electroman; however, are running this so they are making the rules ;)

Brad!

wossname
Sep 9th, 2004, 02:52 PM
Originally posted by brad jones
My assumption is that if it isn't in the rules, then it is fair :D

I'm also assuming there *will* be points for sexiness of code and such.

Pino and Electroman; however, are running this so they are making the rules ;)

Brad!

[Monty Burns]Eeeeexcellent[/Monty burns]

By the way, I will be doing all of my coding while drunk, I expect favoritism for this. :lol:

NoteMe
Sep 9th, 2004, 02:52 PM
Originally posted by wossname

2. My algorithm requires me to specify the first 2 primes (2 and 3) in order for the algorithm to work, is this legal and / or will i be required to generate 2 more primes to compensate?



I was going to ask that next....after I got the rest of the answer, that I have not...:(....

do we have the same algorithm...;)....well BTW read an article on finding primes a year ago. An Indian guy found a new algo that was so good, and also so difficult that only a couple of the guys at MIT or what it is called in USA could follow his lecture...:D

wossname
Sep 9th, 2004, 02:54 PM
And now I expect you want me to waste all my game time researching this mythical alg?

Dude, I didn't come down with the last service pack you know! :D

Nice try.

Pino
Sep 9th, 2004, 02:59 PM
we will deal with all the timing, sure you can test it yourself, but i will set up a routine to time your apps

I will get back to you if it is allowed to use the first 2 prime numbers

Pino
Sep 9th, 2004, 03:02 PM
yes you do get some marks for the presentaion and 'sexiness' of your code, allthough speed is the main concern :) but them few marks could be the differance between 1st and 2nd :)

RobDog888
Sep 9th, 2004, 04:41 PM
Would we be able to know what the current fastest time submitted
is so we could have a target? Of course after you receive the first
project. :D

Also, it was the first 1000 Primes and not just Primes up to 1000.

NoteMe
Sep 9th, 2004, 06:40 PM
Originally posted by RobDog888
Would we be able to know what the current fastest time submitted
is so we could have a target? Of course after you receive the first
project. :D



What will that help? It is still two diffrent machines...and the speed will be very diffrent...

NoteMe
Sep 9th, 2004, 06:52 PM
Ohhhh...one more Q....there is a large number of imperfect prime algorithms out there. Most of them will do the first 1000 primes perfect, but lets say they will add 649539 as a prime withch it is not because it is dividable by 3-3-3-3-3-3-3-3-3-3-11 , and it might skip an other one like 71202143 witch is a prime, but it will still do this test perfect. Will sutch an algorithm be allowed?

dsheller
Sep 9th, 2004, 06:57 PM
Should we count the number 1 as prime?

http://mathworld.wolfram.com/PrimeNumber.html

That states that it is neither prime nor composite.

NoteMe
Sep 9th, 2004, 06:58 PM
Originally posted by dsheller
Should we count the number 1 as prime?

http://mathworld.wolfram.com/PrimeNumber.html

That states that it is neither prime nor composite.


;)



Main Aims

The aim of this contest is to design a program which generates the first 1000 prime numbers and displays them in a standard VB listbox. (Please note that 1 is excluded from being a prime number!)

dsheller
Sep 9th, 2004, 07:03 PM
Bah you can't expect me to read the main aims, the entire directive of the project can you. =)

Acidic
Sep 9th, 2004, 07:07 PM
it does this damn fast. Maybe we should do primes up to a bigger number. or did you mean the first 1000 primes instead?

NoteMe
Sep 9th, 2004, 07:10 PM
Originally posted by Acidic
it does this damn fast. Maybe we should do primes up to a bigger number. or did you mean the first 1000 primes instead?


Main Aims

The aim of this contest is to design a program which generates the first 1000 prime numbers and displays them in a standard VB listbox. (Please note that 1 is excluded from being a prime number!)


:D::D:D:D:D:D

NoteMe
Sep 9th, 2004, 07:12 PM
Hope no one thinks I am spamming now...but for a reference to everyone, here is a list over the first 1000primes, so you can check that your algorithm is right:



2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 53 59 61 67 71
73 79 83 89 97 101 103 107 109 113
127 131 137 139 149 151 157 163 167 173
179 181 191 193 197 199 211 223 227 229
233 239 241 251 257 263 269 271 277 281
283 293 307 311 313 317 331 337 347 349
353 359 367 373 379 383 389 397 401 409
419 421 431 433 439 443 449 457 461 463
467 479 487 491 499 503 509 521 523 541
547 557 563 569 571 577 587 593 599 601
607 613 617 619 631 641 643 647 653 659
661 673 677 683 691 701 709 719 727 733
739 743 751 757 761 769 773 787 797 809
811 821 823 827 829 839 853 857 859 863
877 881 883 887 907 911 919 929 937 941
947 953 967 971 977 983 991 997 1009 1013
1019 1021 1031 1033 1039 1049 1051 1061 1063 1069
1087 1091 1093 1097 1103 1109 1117 1123 1129 1151
1153 1163 1171 1181 1187 1193 1201 1213 1217 1223
1229 1231 1237 1249 1259 1277 1279 1283 1289 1291
1297 1301 1303 1307 1319 1321 1327 1361 1367 1373
1381 1399 1409 1423 1427 1429 1433 1439 1447 1451
1453 1459 1471 1481 1483 1487 1489 1493 1499 1511
1523 1531 1543 1549 1553 1559 1567 1571 1579 1583
1597 1601 1607 1609 1613 1619 1621 1627 1637 1657
1663 1667 1669 1693 1697 1699 1709 1721 1723 1733
1741 1747 1753 1759 1777 1783 1787 1789 1801 1811
1823 1831 1847 1861 1867 1871 1873 1877 1879 1889
1901 1907 1913 1931 1933 1949 1951 1973 1979 1987
1993 1997 1999 2003 2011 2017 2027 2029 2039 2053
2063 2069 2081 2083 2087 2089 2099 2111 2113 2129
2131 2137 2141 2143 2153 2161 2179 2203 2207 2213
2221 2237 2239 2243 2251 2267 2269 2273 2281 2287
2293 2297 2309 2311 2333 2339 2341 2347 2351 2357
2371 2377 2381 2383 2389 2393 2399 2411 2417 2423
2437 2441 2447 2459 2467 2473 2477 2503 2521 2531
2539 2543 2549 2551 2557 2579 2591 2593 2609 2617
2621 2633 2647 2657 2659 2663 2671 2677 2683 2687
2689 2693 2699 2707 2711 2713 2719 2729 2731 2741
2749 2753 2767 2777 2789 2791 2797 2801 2803 2819
2833 2837 2843 2851 2857 2861 2879 2887 2897 2903
2909 2917 2927 2939 2953 2957 2963 2969 2971 2999
3001 3011 3019 3023 3037 3041 3049 3061 3067 3079
3083 3089 3109 3119 3121 3137 3163 3167 3169 3181
3187 3191 3203 3209 3217 3221 3229 3251 3253 3257
3259 3271 3299 3301 3307 3313 3319 3323 3329 3331
3343 3347 3359 3361 3371 3373 3389 3391 3407 3413
3433 3449 3457 3461 3463 3467 3469 3491 3499 3511
3517 3527 3529 3533 3539 3541 3547 3557 3559 3571
3581 3583 3593 3607 3613 3617 3623 3631 3637 3643
3659 3671 3673 3677 3691 3697 3701 3709 3719 3727
3733 3739 3761 3767 3769 3779 3793 3797 3803 3821
3823 3833 3847 3851 3853 3863 3877 3881 3889 3907
3911 3917 3919 3923 3929 3931 3943 3947 3967 3989
4001 4003 4007 4013 4019 4021 4027 4049 4051 4057
4073 4079 4091 4093 4099 4111 4127 4129 4133 4139
4153 4157 4159 4177 4201 4211 4217 4219 4229 4231
4241 4243 4253 4259 4261 4271 4273 4283 4289 4297
4327 4337 4339 4349 4357 4363 4373 4391 4397 4409
4421 4423 4441 4447 4451 4457 4463 4481 4483 4493
4507 4513 4517 4519 4523 4547 4549 4561 4567 4583
4591 4597 4603 4621 4637 4639 4643 4649 4651 4657
4663 4673 4679 4691 4703 4721 4723 4729 4733 4751
4759 4783 4787 4789 4793 4799 4801 4813 4817 4831
4861 4871 4877 4889 4903 4909 4919 4931 4933 4937
4943 4951 4957 4967 4969 4973 4987 4993 4999 5003
5009 5011 5021 5023 5039 5051 5059 5077 5081 5087
5099 5101 5107 5113 5119 5147 5153 5167 5171 5179
5189 5197 5209 5227 5231 5233 5237 5261 5273 5279
5281 5297 5303 5309 5323 5333 5347 5351 5381 5387
5393 5399 5407 5413 5417 5419 5431 5437 5441 5443
5449 5471 5477 5479 5483 5501 5503 5507 5519 5521
5527 5531 5557 5563 5569 5573 5581 5591 5623 5639
5641 5647 5651 5653 5657 5659 5669 5683 5689 5693
5701 5711 5717 5737 5741 5743 5749 5779 5783 5791
5801 5807 5813 5821 5827 5839 5843 5849 5851 5857
5861 5867 5869 5879 5881 5897 5903 5923 5927 5939
5953 5981 5987 6007 6011 6029 6037 6043 6047 6053
6067 6073 6079 6089 6091 6101 6113 6121 6131 6133
6143 6151 6163 6173 6197 6199 6203 6211 6217 6221
6229 6247 6257 6263 6269 6271 6277 6287 6299 6301
6311 6317 6323 6329 6337 6343 6353 6359 6361 6367
6373 6379 6389 6397 6421 6427 6449 6451 6469 6473
6481 6491 6521 6529 6547 6551 6553 6563 6569 6571
6577 6581 6599 6607 6619 6637 6653 6659 6661 6673
6679 6689 6691 6701 6703 6709 6719 6733 6737 6761
6763 6779 6781 6791 6793 6803 6823 6827 6829 6833
6841 6857 6863 6869 6871 6883 6899 6907 6911 6917
6947 6949 6959 6961 6967 6971 6977 6983 6991 6997
7001 7013 7019 7027 7039 7043 7057 7069 7079 7103
7109 7121 7127 7129 7151 7159 7177 7187 7193 7207
7211 7213 7219 7229 7237 7243 7247 7253 7283 7297
7307 7309 7321 7331 7333 7349 7351 7369 7393 7411
7417 7433 7451 7457 7459 7477 7481 7487 7489 7499
7507 7517 7523 7529 7537 7541 7547 7549 7559 7561
7573 7577 7583 7589 7591 7603 7607 7621 7639 7643
7649 7669 7673 7681 7687 7691 7699 7703 7717 7723
7727 7741 7753 7757 7759 7789 7793 7817 7823 7829
7841 7853 7867 7873 7877 7879 7883 7901 7907 7919

MartinLiss
Sep 9th, 2004, 07:13 PM
Pino, do you mean the primes between 2 and 1000, or the first thousand primes. Those are two very different things.

NoteMe
Sep 9th, 2004, 07:18 PM
Originally posted by MartinLiss
Pino, do you mean the primes between 2 and 1000, or the first thousand primes. Those are two very different things.


Didn't you see he has edited the post...I have all ready higlighted it once...and I will do it again...:D


Main Aims

The aim of this contest is to design a program which generates the first 1000 prime numbers and displays them in a standard VB listbox. (Please note that 1 is excluded from being a prime number!)

NoteMe
Sep 9th, 2004, 07:21 PM
Are we allowed to assume that 7919 is the biggest of the primes we will find?

Acidic
Sep 9th, 2004, 07:24 PM
Not, I think we are. While not making perfect software you'll have filled all the criteria, which is what is needed.
So now to google for good ideas on improving this code.

StevenHickerson
Sep 9th, 2004, 07:26 PM
Hehe well I got my code otpimized as much as I can.. wish I knew what other's speeds where.. lol I'd hate to submit mine only to discover I was three times slower than the winner... although I believe my speed is a descent speed for the job.

Ex-FB
Sep 9th, 2004, 07:40 PM
Er, how are you going to time the calculation. Because for the 1st 1000 primes, it's going to be so fast that I'm not sure the windows timer is going to be up for the job (unless you're going to test it on a slow machine). Maybe you should consider more than the 1st 1000.... just a thought.

NoteMe
Sep 9th, 2004, 07:58 PM
Lots of questions here..:D Trying to bend the rules...;)


Are we allowed to asume that even numbers not are primes?

Electroman
Sep 9th, 2004, 08:10 PM
Posted by NoteMe
Ohhhh...one more Q....there is a large number of imperfect prime algorithms out there. Most of them will do the first 1000 primes perfect, but lets say they will add 649539 as a prime withch it is not because it is dividable by 3-3-3-3-3-3-3-3-3-3-11 , and it might skip an other one like 71202143 witch is a prime, but it will still do this test perfect. Will sutch an algorithm be allowed? Well I would have thought it was clear, thats why we said the first 1000, the algo must only work for the first 1000 after that who cares ;).


Posted by NoteMe
Are we allowed to assume that even numbers not are primes? Considering even numbers aren't prime :rolleyes:. The only thing we will be testing is the speed of the algo and the result is correct for the first 1000 primes.



BTW you may notice that the the contest is acceptign both VB.NET & VB6 so there should also be two winners because the speed of a VB.NET program and VB6 can't be compared fairly ;).

Electroman
Sep 9th, 2004, 08:16 PM
Posted by RobDog888
Would we be able to know what the current fastest time submitted
is so we could have a target? Of course after you receive the first
project. :D

Also, it was the first 1000 Primes and not just Primes up to 1000. None of the submitted projects will be viewed (by anyone) untill the closing date, and then all the entries will become visible to everyone while we judge.
Notice that this is due to change as we haven't fully decided if you will see the other entries as soon as the deadline is reached or will have to wait till we have judged them.

The times of every sample will be given at the end of it and will be tested on several different machines too. The VB6 & VB.NET ones may be tested on different machines to those aswell because like myself I only have VB6 & not VB.NET :(.

The GetTickCount() API should be suitable but if the length of time is below 100ms (or in that area) I suggest we chnage it to use the Performance Counter (if we don't use it anyway).

NoteMe
Sep 9th, 2004, 08:19 PM
Originally posted by Electroman

Considering even numbers aren't prime :rolleyes:. The only thing we will be testing is the speed of the algo and the result is correct for the first 1000 primes.



OK...have hardcoded the 1000 first primes into the listbox now....thanks and good bye...;)

alkatran
Sep 9th, 2004, 08:26 PM
Sexyness of code? What type of code 'turns you on'? Well commented? "l"s in front of longs? Really obsfucated code? (GOTO HEAVEN!)

dsheller
Sep 9th, 2004, 08:27 PM
Originally posted by NoteMe
OK...have hardcoded the 1000 first primes into the listbox now....thanks and good bye...;)

NoteMe wins by being a cheater =)

Electroman
Sep 9th, 2004, 08:31 PM
Yea I think as a limitation we should limit the amount of hardcoded primes by saying it should be reasonable for the algorythm and no more than it requires. The other choice is limiting it to just two but I think this is more sensible.

BTW if your algorythm only works for the primes after the first 100 then you can't hardcode the first 100 you'll have to use two algorythms, the first to get the first 100 and if the other is faster you'll then want to make it switch over to the other one for the last 900 ;).

Ex-FB
Sep 9th, 2004, 08:37 PM
Originally posted by Electroman

The GetTickCount() API should be suitable but if the length of time is below 100ms (or in that area) I suggest we chnage it to use the Performance Counter (if we don't use it anyway). [/B]

Thanks.

Sorry to add another question, but do you want us to include the timing code ourselves, and I'm assuming it's from when the user presses the Start button, or do you want it to start calculating in the load/sub_main event and display the results as soon as possible?

Electroman
Sep 9th, 2004, 08:38 PM
Posted by alkatran
Sexyness of code? What type of code 'turns you on'? Well commented? "l"s in front of longs? Really obsfucated code? (GOTO HEAVEN!) I dunno how that will work but myself I would recommend indenting your code (how much doesn't matter) but there is nothing I hate more than code that isn't indented. As for the hungarian notation I personally don't like it. I guess for appearance of code it will be marked by all the judges and then an average used.
I wouldn't down mark someone for using Hungarian notation but if they used silly names for the variables (e.g. BillyBob, SamFoo, NoteMe, Patato) then I would do though.

Saying that I don't even know if I will be judging this one, unsure if we decided that one yet :doh:. I guessed this one will be by the moderators and pino :DontQuoteMeOnThis:.

Electroman
Sep 9th, 2004, 08:41 PM
Posted by Ex-FB
Thanks.

Sorry to add another question, but do you want us to include the timing code ourselves, and I'm assuming it's from when the user presses the Start button, or do you want it to start calculating in the load/sub_main event and display the results as soon as possible? I think it'll be better if we add the timing code, that way it ensures its the same for every entry. If we create it as an extra module then it can be added and just a couple of lines in the submitted code will be it.

If we get this module made in time we could release it to you so you can't test yourselfs and find th optimium algo. Ofcourse the numbers are gonna be different for different machines but at least you'll be able to compare chnages you make to your own ;).

alkatran
Sep 9th, 2004, 08:48 PM
Originally posted by Electroman
I dunno how that will work but myself I would recommend indenting your code (how much doesn't matter) but there is nothing I hate more than code that isn't indented. As for the hungarian notation I personally don't like it. I guess for appearance of code it will be marked by all the judges and then an average used.
I wouldn't down mark someone for using Hungarian notation but if they used silly names for the variables (e.g. BillyBob, SamFoo, NoteMe, Patato) then I would do though.

Saying that I don't even know if I will be judging this one, unsure if we decided that one yet :doh:. I guessed this one will be by the moderators and pino :DontQuoteMeOnThis:.

What if I do the opposite of indenting? You know, indenting the lines outside a loop? :afrog:

I'm including my own timing code, but it can be removed easily (only 3 lines, using gettickcount). Problem though, it doesn't always return the same value? Range from .47s to .58s, but I have things running. Will the timing tests be done multiple times, and the average taken?

NoteMe
Sep 9th, 2004, 08:50 PM
Originally posted by alkatran
What if I do the opposite of indenting? You know, indenting the lines outside a loop? :afrog:

I'm including my own timing code, but it can be removed easily (only 3 lines, using gettickcount). Problem though, it doesn't always return the same value? Range from .47s to .58s, but I have things running. Will the timing tests be done multiple times, and the average taken?

I wish Pino answered this yesterday....I have asked all of these questions in PMs to Pino, and he didn't answer them well...:D....BTW GetTickCount is not good enough...;)....it has tooo big Ticks...;)

Merri
Sep 9th, 2004, 08:51 PM
Ok, at the moment my results with 30000 primes is that it is faster to calculate the primes than filling the listbox with the items (unless I set ListBox hidden while populating it).

My suggestion for the benchmarking is to run the code a few million times or more doing the same call and then time that. Place the code behind a command button, it makes benchmarking a whole lot easier. Times may vary a lot with GetTickCount (up to 300 ms at worst), so the longer it takes to test, the more accurate the results will be.

Also, I suggest turning all of the advanced optimizations on when you compile the benchmarks. It really does matter a lot. And if someone have made a code that doesn't work with advanced optimizations... well, too bad. Error checking is important! :D


Edit I'm currently at 7 ms. I included all code within the check, including clearing the listbox. We can't compare the times too well though, different computers.

NoteMe
Sep 9th, 2004, 08:55 PM
I have tested a lot today...and it looks like the simples ways of calculating the 1000 first primes is the fastest ones...advanced algoritms takes to much time on soooo few primes.....I will go to bed now and see if the number will be raised, if so then there will be some more advanced code winning then the simplest one...and I would have to change it after all..

alkatran
Sep 9th, 2004, 09:05 PM
Wow, 7 milliseconds. I just chopped mine from .46 to .16
Although I haven't exactly researched it much.

Also, I fill an array with the primes, then get the time, THEN do all the output. We are timing the generation, after all. Method of output (file, listbox) shouldn't affect score.

Um, you are finding the first 1000 primes, and not the primes up to 1000, right?

Electroman
Sep 9th, 2004, 09:08 PM
Posted by alkatran
What if I do the opposite of indenting? You know, indenting the lines outside a loop? :afrog:

I'm including my own timing code, but it can be removed easily (only 3 lines, using gettickcount). Problem though, it doesn't always return the same value? Range from .47s to .58s, but I have things running. Will the timing tests be done multiple times, and the average taken? You might want to remove that before submitting your code. Mainly because its extra overhead, we won't go thoguh the code and comment out things like this ;).


As for the point with the populating the listbox taking up alot of time I suggest when its judged we comment out the lines that populate the listbox when doing the speed tests but uncomment them for checking the values ;).

Another option would be if the algo just put the values in a simple array then after that another funtion puts the array into the listbox afterwards. That way we can exclude the final stage when timing ;).

Merri
Sep 9th, 2004, 09:13 PM
Just set ListBox.Visible = False before you start populating it and ListBox.Visible = True after you're done. My 7 ms includes filling the and clearing the listbox.

Edit When I take out the clearing and hiding/viewing the listbox, I get into 5 ms. If I wouldn't populate the listbox within the main loop, I'd probably go under 1 ms.

Edit #2 Yup, it goes under 1 ms. I get 30000 primes in 100 ms.

dsheller
Sep 9th, 2004, 09:14 PM
That sounds like a good idea, shut off all non system critical processes, and then take the average of the values it returns.

Acidic
Sep 9th, 2004, 09:59 PM
:( :( My time sucks badly. I realise that my PC is different and that I have a hell of a lot of applications running in the background. It's still bad.:( :(

NoteMe
Sep 9th, 2004, 10:01 PM
My time too...:D...But I am struggeling more with trying to remember how VB worked...:D

RobDog888
Sep 9th, 2004, 10:03 PM
1 ms! I kinda thought that Merri would be the one at the top
when all the dust settles. I'm not even below 100ms yet. This is
just what I wanted to know.

NoteMe
Sep 9th, 2004, 10:05 PM
Still wondering what PC he has...and if he ran it in the IDE or as an EXE...

NoteMe
Sep 9th, 2004, 10:10 PM
For everyone that is trying and don't know how to time their apps properly here is a class that the good old Platipus made some years ago. Don't think I have changed much in it. So the credit goes to him.


Here is how you should use it:



Private Sub cmdCrunch_Click()

Dim Q As New sTime

Q.Init

Q.StartTime
findPrimes2 'Call your function
Q.StopTime

MsgBox Q.RetTime

End Sub

NoteMe
Sep 9th, 2004, 10:17 PM
Well 19ms...:D:..I'll blame my PC for that...hehe

StevenHickerson
Sep 9th, 2004, 10:37 PM
Geeze do you guys just have those algo's just sitting around? lol.

I've never worked with prime numbers before and just from reading up today and making my own algo I got down to a time of 300 ms... I thought that was pretty impressive, yall are sitting here talking about 19, 7, and 1 even!..... Dosn't that kind of just ruin the spirit of the contest lol.

After the contest is over if I could get my hands on one of those algos just to see how it works I'd be gratefull :)

RobDog888
Sep 9th, 2004, 10:39 PM
503ms with 100% accuracy using a recordset! Fast for a rs but still bad :(
Just want to know what the difference would be.

Now I will try using a different method. Should be much much
faster!

RobDog888
Sep 9th, 2004, 10:40 PM
Originally posted by StevenHickerson
After the contest is over if I could get my hands on one of those algos just to see how it works I'd be gratefull :) They are going to post the winning project, I believe, after the contest is over.

Ex-FB
Sep 9th, 2004, 10:45 PM
Originally posted by NoteMe
Still wondering what PC he has...and if he ran it in the IDE or as an EXE...

Gettin 2.8ms on a 2.4 Celeron.... (compiled in VB6) if that helps (that's including populating and showing the listbox).

Still lot's more to do... I like this.

alkatran
Sep 9th, 2004, 11:05 PM
You guys are getting your times in the IDE too, right?

Ex-FB
Sep 9th, 2004, 11:43 PM
7.9ms in the IDE, but that's probably not as good a test, as a lot of the efficiencies only show up at compilation.

Ex-FB
Sep 9th, 2004, 11:46 PM
Originally posted by StevenHickerson

I've never worked with prime numbers before and just from reading up today and making my own algo I got down to a time of 300 ms... I thought that was pretty impressive, yall are sitting here talking about 19, 7, and 1 even!..... Dosn't that kind of just ruin the spirit of the contest lol.


It's just for fun. Regardless of who wins, who cares, I for one still enjoy little challenges like this. It's like crossword puzzles in newspapers, it get's the brain juices flowing. :)

alkatran
Sep 9th, 2004, 11:56 PM
Upon compilation I get times of .02 s and lower. Using gettickcount, this means it could be anywhere from 0.5 to -0.5. :rolleyes: :D

RobDog888
Sep 10th, 2004, 12:02 AM
Download the sTime class and add it into your command button event.

I'm getting 0.058s according to the class timer which seems
accurate accross several runs. Didnt vary more than 0.001s overy
25 runs.

RobDog888
Sep 10th, 2004, 12:06 AM
After another modification - but no adding to listbox. So this
would be 0.0003s? Right?

http://www.vbforums.com/attachment.php?s=&postid=1783691

RobDog888
Sep 10th, 2004, 12:18 AM
Hey Mods, are we allowed to make more than one entry for
this contest?

:confused:

Pino
Sep 10th, 2004, 02:08 AM
Hey all wow, over night there has been a lot of replies, i have allready set up a timing system :) you guys just worry about the coding,

I will most likly compile the code, but if it gets to close run it from the ide

my system

pentium 4 2.6ghz :)

i'm going to have to rfead through your questions, i'll answer as many as i can

Pino
Sep 10th, 2004, 02:09 AM
Originally posted by RobDog888
Hey Mods, are we allowed to make more than one entry for
this contest?

:confused:

no :) 1 entry per user

Pino
Sep 10th, 2004, 02:10 AM
Originally posted by RobDog888
They are going to post the winning project, I believe, after the contest is over.

yep all the apps become visible so you can all take a look

Pino
Sep 10th, 2004, 02:14 AM
Originally posted by NoteMe
I wish Pino answered this yesterday....I have asked all of these questions in PMs to Pino, and he didn't answer them well...:D....BTW GetTickCount is not good enough...;)....it has tooo big Ticks...;)

i thought i answered this note me :confused: You can add your own timings but please remove them before submiting as i have set up my own timing system

yes i will take the average of a group of data :)

Listen guys dont get hooked up on how i am going to time it, just develop the fastest most efficiant code you can :)

Merri
Sep 10th, 2004, 04:16 AM
The class module NoteMe provided isn't giving good results on too fast codes. The times it gives makes no sense to me. First it can give something like:

8.22something
7.9something
1.7something

And when I change to 30000 primes, I can get the same as above and 0.100something

Only the last one matched somehow with the time given by my module. I guess the class module would love to get a longer taking code.


Edit I have Athlon XP 2200+ @ 1800 MHz

NoteMe
Sep 10th, 2004, 04:34 AM
Originally posted by Merri
The class module NoteMe provided isn't giving good results on too fast codes. The times it gives makes no sense to me. First it can give something like:

8.22something
7.9something
1.7something

And when I change to 30000 primes, I can get the same as above and 0.100something

Only the last one matched somehow with the time given by my module. I guess the class module would love to get a longer taking code.


Edit I have Athlon XP 2200+ @ 1800 MHz

It is given in seconds....and watch out, when the numbers are small VB uses sientific numbers...;) Make sure it is not 8.22*10^(-2)...;) It uses the E you know...;)



Update: 6Ms in my IDE
Exe : 4Ms


Using 1,4Ghz CPU



Maybe If Pino have a kick ass GPU, it would nearly 100% for sure be faster to write a shader, and let the GPU do the crunching...:D...am I allowed..:D..J/K....

NoteMe
Sep 10th, 2004, 04:58 AM
Are we allowed to use InLine ASM?

Arun.NS
Sep 10th, 2004, 08:21 AM
To measure the time for the VB .Net code use the following timer. I think this is quite accurate and consistent and simple to add to ur code.

http://www.mentalis.org/soft/class.qpx?id=8

Best of luck..:thumb:

Cheers,
Arun.

Acidic
Sep 10th, 2004, 08:29 AM
Originally posted by NoteMe
Are we allowed to use InLine ASM?
No! I hope

I'm just making sure, comments don't matter at all do they? I mean, when you compile it, all the coments are gotten rid of right?

brad jones
Sep 10th, 2004, 08:44 AM
Just some comments:

Timing will be done on the code you submit. This means if there is timing code in your listing or any other bells and whistles, it will be timed as well. (and thus increase your program's exexcution time). The judges will not comment or remove code in any way for the timings.

If the rules don't say it, then it is fair. I was going to actually do a hardcoded listing of the prime numbers as well - because that didn't violate the rules. Granted, this would not be a very 'sexy' solution, thus while it might be fastest, I doubt it would win.

If there are changes to the rules after a contest has started, then those changes need to be highlighted with the[hl] tag and anyone that has submitted needs to be able to resubmit.

Brad!

Electroman
Sep 10th, 2004, 09:05 AM
Just to let you know, for those that have ventured into the entries sub-forum already. I have altered the instructions for posting your entries. It did read that you should reply to the thread already there but it now says you should create a new thread for each entry.

NoteMe
Sep 10th, 2004, 09:05 AM
Originally posted by brad jones

If the rules don't say it, then it is fair. I was going to actually do a hardcoded listing of the prime numbers as well - because that didn't violate the rules. Granted, this would not be a very 'sexy' solution, thus while it might be fastest, I doubt it would win.



Don't steal my idea...:D

NoteMe
Sep 10th, 2004, 09:07 AM
Originally posted by Acidic
No! I hope

I'm just making sure, comments don't matter at all do they? I mean, when you compile it, all the coments are gotten rid of right?

True...they are ignored by the compiler...and will not make a diffrence for others then the mods that will read the code



An other question...will the test be in the IDE or Compiled...if it is in the IDE then I hate you, and if it is compiled....what kind of CPU do you have Pino...what brand/type/speed and so on...:D

Electroman
Sep 10th, 2004, 09:10 AM
Posted by NoteMe
An other question...will the test be in the IDE or Compiled...if it is in the IDE then I hate you, and if it is compiled....what kind of CPU do you have Pino...what brand/type/speed and so on...:D Out of fairness it would be likely that more than one PC will be used, I would also suggest its run in the IDE, we don't want the speeds to be too fast to measure now ;).

Acidic
Sep 10th, 2004, 09:17 AM
Maybe you should use one of those old 25MHz processor PCs. I have one somewhere, no hold on, it's in sweden, and its HDD is here.

NoteMe
Sep 10th, 2004, 10:12 AM
Originally posted by Acidic
Maybe you should use one of those old 25MHz processor PCs. I have one somewhere, no hold on, it's in sweden, and its HDD is here.

Probably not a 32bit processor..:D...or maybe it is...well anyway...NO WAY...:D

Ex-FB
Sep 10th, 2004, 10:38 AM
Originally posted by Electroman
Out of fairness it would be likely that more than one PC will be used, I would also suggest its run in the IDE, we don't want the speeds to be too fast to measure now ;).

Ah - but some efficiencies of code, only appear when you compile the program and aren't applicable to the interpreted version.

NoteMe
Sep 10th, 2004, 12:18 PM
Originally posted by Ex-FB
Ah - but some efficiencies of code, only appear when you compile the program and aren't applicable to the interpreted version.


Exactly...I wote for Native code...

Ex-FB
Sep 10th, 2004, 12:31 PM
Me too....... god help me if it comes down "sexyness" of code, as mine looks like a dogs dinner (and I've broken more than one of the cardinal rules of programming) :p

wossname
Sep 10th, 2004, 01:45 PM
What sort of timings are people getting?

I just maxed out at a rather uninspiring 10ms (generation, listbox insertion and display) as an average of runs 2, 3 and 4.

Its as fast as this algorithm will go on my machine (1.5ghz Celery processor). I'm using GetTickCount though and the lowest resolution that it has is about 10ms anyway, so it could be a little faster than that :) Does anyone know what timing methods the mods are going to use?

But I'm happy to say I invented the alg about 2 years ago. I hope it is unique (I bet its not though, I have a sneaking suspicion that NoteMe is using the same or similar).

I'm ready to submit my work now but the thread is closed :(

Pino
Sep 10th, 2004, 02:17 PM
Originally posted by wossname
What sort of timings are people getting?

I just maxed out at a rather uninspiring 10ms (generation, listbox insertion and display) as an average of runs 2, 3 and 4.

Its as fast as this algorithm will go on my machine (1.5ghz Celery processor). I'm using GetTickCount though and the lowest resolution that it has is about 10ms anyway, so it could be a little faster than that :) Does anyone know what timing methods the mods are going to use?

But I'm happy to say I invented the alg about 2 years ago. I hope it is unique (I bet its not though, I have a sneaking suspicion that NoteMe is using the same or similar).

I'm ready to submit my work now but the thread is closed :(

You have to make a new thread :)

NoteMe
Sep 10th, 2004, 02:59 PM
Originally posted by wossname

But I'm happy to say I invented the alg about 2 years ago. I hope it is unique (I bet its not though, I have a sneaking suspicion that NoteMe is using the same or similar).



It won't help as long as Merri is faster...someone with more time on their hands then me needs to beat that guy....:D

wossname
Sep 10th, 2004, 03:08 PM
I just submitted my entry.

So what has Merri got under the hood of his app then? Anything we've heard of?

Acidic
Sep 10th, 2004, 03:48 PM
I get 1.3 in the IDE and 1 when it's compiled. This is in a 1.9 MGHz thingy. That includes everything. I know it needs to be faster.

aah, damn me for not thinking of this earlier. 1 in IDE, 0.8 compiled. I didn't think to not check with numbers that are greater than 1/2 the number i'm currently at.

NoteMe
Sep 10th, 2004, 06:38 PM
Originally posted by Acidic
I get 1.3 in the IDE and 1 when it's compiled. This is in a 1.9 MGHz thingy. That includes everything. I know it needs to be faster.

aah, damn me for not thinking of this earlier. 1 in IDE, 0.8 compiled. I didn't think to not check with numbers that are greater than 1/2 the number i'm currently at.


Not you too...well then it is two and a half persons that is faster then me...:D

NoteMe
Sep 10th, 2004, 11:24 PM
I emulated PragmaPack from C++ and made the nicest algo untill now....it is sooooo nice and fast....does 1,000,000 primes in less then a second on my 1,4Ghz (without adding to list box) the problem is that it is impossible to add all the entries in that loop, so I have to have an other loop after it, and at compiled that makes it do 1000 primes in 4.3-4.4ms, that is a bit slower then the old boring algo that does 1000 primes in 4.2-4.3, hmmmm....what should I submit, the sexy pragma pack code that is 0.1-0.2ms slower or the fastest one....I can't win over Merris speed anyway....


ии

mendhak
Sep 11th, 2004, 02:56 AM
I have a bit of a confusion here.

Adding 1000 items to a listbox itself takes a considerable number of milliseconds. For example, with a very simple loop, like this:


Dim tm As Integer
Dim i As Integer

tm = Environment.TickCount

For i = 1 To 1000
ListBox1.Items.Add(i.ToString)
Next

Console.WriteLine(Environment.TickCount - tm)



I got 40 ms.

How is it that some of you are able to generate the primes and populate the listbox in less than 4 ms?

:confused:

The best I've gotten so far, including generation and population of the listbox is 42 ms.

(See that wossname? 42!!) :D

StevenHickerson
Sep 11th, 2004, 03:16 AM
mendhak set your box invisible before you add and visible after you add :).. VB is trying to refresh the listbox view while your adding stuff.

mendhak
Sep 11th, 2004, 03:41 AM
Yes, thanks. Also, I looked through Listbox's properties, and found a bunch of methods they've included for efficiency.

I am now down to 8ms.

Might as well submit it, then. I'd really like to see if I come in at position # 42. :D

I am very interested to see what others have written.

Pino
Sep 11th, 2004, 03:53 AM
Ok after looking at some timings code we are going to use noteme's timing method :) simply because you can all test your code :) and it does the job

(if this is still ok with noteme, if not please contact me)

Stime

You can find it on the second page of this thread!

mendhak
Sep 11th, 2004, 04:25 AM
Originally posted by Pino
Ok after looking at some timings code we are going to use noteme's timing method :) simply because you can all test your code :) and it does the job

(if this is still ok with noteme, if not please contact me)

Stime

You can find it on the second page of this thread!

That's for VB6. I wouldn't like to use it in VB.NET. I'm using this for timing right now, someone had posted a link to it in this thread:





Imports System
Imports System.Runtime.InteropServices

Namespace Org.Mentalis.Utilities

Public NotInheritable Class StopWatch
Private m_StartTime As Long
Private m_Frequency As Long
Private Declare Ansi Function QueryPerformanceCounter Lib "kernel32.dll" (ByRef x As Long) As Integer
Private Declare Ansi Function QueryPerformanceFrequency Lib "kernel32.dll" (ByRef x As Long) As Integer
Public Sub New()
Frequency = GetFrequency()
Reset()
End Sub
Public Sub Reset()
StartTime = GetValue()
End Sub
Public Function Peek() As Long
Return CType((((GetValue() - StartTime) / CType(Frequency, Double)) * 10000), Long)
End Function
Private Function GetValue() As Long
Dim ret As Long = 0
If QueryPerformanceCounter(ret) = 0 Then Throw New NotSupportedException("Error while querying the high-resolution performance counter.")
Return ret
End Function
Private Function GetFrequency() As Long
Dim ret As Long = 0
If QueryPerformanceFrequency(ret) = 0 Then Throw New NotSupportedException("Error while querying the performance counter frequency.")
Return ret
End Function
Private Property StartTime() As Long
Get
Return m_StartTime
End Get
Set(ByVal Value As Long)
m_StartTime = Value
End Set
End Property
Private Property Frequency() As Long
Get
Return m_Frequency
End Get
Set(ByVal Value As Long)
m_Frequency = Value
End Set
End Property

End Class
End Namespace



To use it,


Dim sw As New StopWatch

'your code, etc etc

Label1.Text = (sw.Peek() / 10).ToString 'Time elapsed.

wossname
Sep 11th, 2004, 05:25 AM
Mend, what unit of time is that giving out? Milliseconds?

Sadly my app just can't compete with the big boys.

My algorithm just aint powerful enough. :(

mendhak
Sep 11th, 2004, 06:57 AM
Originally posted by wossname
Mend, what unit of time is that giving out? Milliseconds?

Sadly my app just can't compete with the big boys.

My algorithm just aint powerful enough. :(

It gives out tens of milliseconds. :ehh:

Which is why when you want the milliseconds, you must divide by 10.

And don't worry, my algo has been written in such a way that it'll always be almost but not quite, as powerful as yours. :) I think I should be getting extra points just for the prophetic powers of my algo :D

How did you time yours, btw? I hope you're not using the Environment.GetTick. :sick:

mendhak
Sep 11th, 2004, 07:29 AM
Submitted.

Electroman
Sep 11th, 2004, 08:41 AM
Posted by mendhak
It gives out tens of milliseconds. :ehh:

Which is why when you want the milliseconds, you must divide by 10. So does that mean its only acurate to every 10ms? or Tenths of ms?


BTW I'm not sure if I said this before in this thread but you know the VB6 & VB.NET ones will be judged seperatly so there should be two winners, the speed of a VB6 app & VB.NET app can't really compete fairly? :)


P.S. Which one is Merri using? ;)

NoteMe
Sep 11th, 2004, 08:42 AM
Originally posted by mendhak
Yes, thanks. Also, I looked through Listbox's properties, and found a bunch of methods they've included for efficiency.



WHat properties was that....I turned them on an off all night yesterday, and came no where...:D...maybe it only works for .NET.....I don't have that..well we have it at school tho'....

NoteMe
Sep 11th, 2004, 08:44 AM
Originally posted by Pino
Ok after looking at some timings code we are going to use noteme's timing method :) simply because you can all test your code :) and it does the job

(if this is still ok with noteme, if not please contact me)

Stime

You can find it on the second page of this thread!

No problem. It was the good old Platipus that started that code anyway. Havn't changed much in it. And he never minded us using it in the game section to test the speed of diffrent implementations, so then I guess he won't mind this either...

mendhak
Sep 11th, 2004, 09:56 AM
Originally posted by NoteMe
WHat properties was that....I turned them on an off all night yesterday, and came no where...:D...maybe it only works for .NET.....I don't have that..well we have it at school tho'....

I don't think it's there in VB6. I don't have VB6 on this machine, or I'd check. PM Wossy for more info, I think he's using the same thing. :D

wossname
Sep 11th, 2004, 10:28 AM
:lol:

I've submitted my app but I am still playing with my code.

Ignoring the listbox entirely and just timing the algorithm, I can get 2ms, I'm happy with that :D (1.5ghz celeron, XP Home edition), with browser and IDE running at the same time.

The Listbox should be banned for being a resource hog. :D

NoteMe
Sep 11th, 2004, 12:04 PM
Originally posted by wossname
:lol:

I've submitted my app but I am still playing with my code.

Ignoring the listbox entirely and just timing the algorithm, I can get 2ms, I'm happy with that :D (1.5ghz celeron, XP Home edition), with browser and IDE running at the same time.

The Listbox should be banned for being a resource hog. :D

I completly agree....my algo takes less then 1ms without the Listbox, the list box it self takes 4,5ms or so in the IDE...:D

NoteMe
Sep 11th, 2004, 12:27 PM
Everyone that feels the same way as me about compiled versus IDE timing of our apps. Please add this to your Form_Load event:


On Error Resume Next
Debug.Print 1 / 0
If Err Then
MsgBox "The contest should only be ran with compiled apps." & vbCrLf & "Please Compile this app.", , "Please Compile"
End If


Or if you realy dare:

On Error Resume Next
Debug.Print 1 / 0
If Err Then
MsgBox "The contest should only be ran with compiled apps." & vbCrLf & "Please Compile this app.", , "Please Compile"
Unload Me
End If

wossname
Sep 11th, 2004, 02:48 PM
On Error Resume Next
Debug.Print 1 / 0
If Err Then
CorruptWindowsPartition() ':D :lol:
Unload Me
End If

Pino
Sep 11th, 2004, 02:56 PM
dont want to sound like a kill joy but could we keep this thread for questions relating to the contest and not chit chat :)

vbasicgirl
Sep 11th, 2004, 04:17 PM
i think i will have a go even though i have never worked with prime numbers before just for experience.

my question is, will the code have to be NON api or does anything go.

thank you.
casey.

Pino
Sep 11th, 2004, 04:31 PM
you can do anything with your app as long as you follow the rules, the rules specify you must

generate the first 1000 prime numbers
display them ina listbox
and not use 3rd party controls :)

RobDog888
Sep 11th, 2004, 04:47 PM
How about, just to make it more interesting, not allowing the use
of any of the popular algorithms. As most know, all you have to
do is google prime numbers or such and you can find an accurate
algorithm. Not much competition in copying someone elses
formula.

:D

dsheller
Sep 11th, 2004, 05:45 PM
Well think of it this way rob, if me and merri use the same algorithm one of us will implement it in a more efficient manner ( no not me ).

RobDog888
Sep 11th, 2004, 05:56 PM
Yes, but I was just thinking that there are going to be many
entries using the same alogo. Keeping those popular alogos out
would make it interesting to see the creativity factor come into
play. No biggie though. I know mine is fast, but not as fast as
Merri's. Dont seem very competitive now. As I'm sure others know
that they cant beat Merri either. Nothing against Merri to say the
least.

:)

NoteMe
Sep 11th, 2004, 06:16 PM
Originally posted by Pino
dont want to sound like a kill joy but could we keep this thread for questions relating to the contest and not chit chat :)

So again....to get the final answer....will the testing be done after you have compiled it, or in the IDE.....for some implementations it is a big diffrence because of the way 32bit CPUs work....

And yeah. I am still voting for compiled code. Thats what the app would have been in the real world anyway.....


ии

NoteMe
Sep 11th, 2004, 07:50 PM
No no no..don't post it here.....

ntg
Sep 11th, 2004, 10:44 PM
Darn it, the first time through is always slower than consecutive times. Getting slightly different timing results from consecutive runs (am using posted StopWatch.vb class).

Average results: 0,5 ms for calculating and 0,8 ms totally. Using .Net on P4@2.4Ghz.

Cheers,
NTG

Electroman
Sep 11th, 2004, 10:48 PM
You should all feel comfort in the fact my machine will probably run them all below 1ms: 3GHz (800 FSB, hyperThreading) 2GB 400MHz Dual Channel DDR :D

Problem is I can only do the VB6 ones as I don't have the VB.NET IDE :(.

dsheller
Sep 11th, 2004, 10:51 PM
Although you said third party controls are disallowed, could we possibly use our own controls if we just wrap code in them?

Pino
Sep 12th, 2004, 05:14 AM
I will initially run it through my 2.6ghz pc if the timing are all very close might try it ona slower machine as well (400 mhz) :)

ntg
Sep 12th, 2004, 08:09 AM
Hey, I think I've posted on the wrong place :cry:
I created a new thread at VBForums.com>General>VBForums Coding Contests>Contest Entries. Is that ok or should I create a new thread at VBForums.com>General>VBForums Coding Contests>Contest Entries>Prime Numbers Entry Thread ?

Cheers,
Nick

Electroman
Sep 12th, 2004, 08:50 AM
Posted by ntg
Hey, I think I've posted on the wrong place :cry:
I created a new thread at VBForums.com>General>VBForums Coding Contests>Contest Entries. Is that ok or should I create a new thread at VBForums.com>General>VBForums Coding Contests>Contest Entries>Prime Numbers Entry Thread ?

Cheers,
Nick yea the first one was right, the entries don't become visible untill the contest is over ;).

Merri
Sep 12th, 2004, 01:48 PM
First of all, I'd never touch .NET unless I'd need it in my job (and my current job isn't programming related ;)). So yeah, I'm doing it with pure VB6: no API, no type libraries, no assembler etc. With a listbox it takes the steady 5 ms to show 1000 primes in the listbox (9 ms in the IDE). I formatted my code so that if the people who time the codes want to, they can leave out the listbox.

As for the algorithm, it is my own, since I didn't find any premade one. This is the first time I'm doing something with the prime numbers :) I have no idea what algorithms others might have.

Current version can count up to 32767 prime numbers (as many as you can put in the listbox without errornous behavior) at about 250 ms, listbox slowdown included (730 ms in IDE). I might submit this as it is now, as I guess I can do only minor optimization from now on that doesn't really matter.


Edit I got interested on seeing more accurate results. I took out the listbox from the timing, made the whole algorithm loop 100 times and these are my results for single run times:

- 0,83 ms to get 1000 primes compiled
- 5,22 ms to get 1000 primes under IDE
- 117 ms to get 32767 primes compiled
- 620 ms to get 32767 primes under IDE

Halsafar
Sep 12th, 2004, 01:57 PM
What do we win?

I can use VB6 right? I've never heard it called legacy before...

Use a PerformanceCounter to do code tests...that has been the choice for the last 10 years as far as I know. Most routines run so fast that gettickcount or window timer never can get an accurate reading. Performance counter works in nano-seconds so it is accurate...almost.

This is a little to easy, and being there are only a few ways to achieve this, you should declare you want a unique way of finding prime numbers...Im' sure people could come up with a million mods of the basic prime number routine...I'd like to see something really unique.

NotLKH
Sep 12th, 2004, 02:00 PM
Hows .0455 Seconds, compiled, Avweraged over 11 loops, Clearing and Populating the listbox every loop, sound on a 400 mHz HP?

:wave:
-Lou

Pino
Sep 12th, 2004, 02:10 PM
Originally posted by Halsafar
What do we win?

I can use VB6 right? I've never heard it called legacy before...

Use a PerformanceCounter to do code tests...that has been the choice for the last 10 years as far as I know. Most routines run so fast that gettickcount or window timer never can get an accurate reading. Performance counter works in nano-seconds so it is accurate...almost.

This is a little to easy, and being there are only a few ways to achieve this, you should declare you want a unique way of finding prime numbers...Im' sure people could come up with a million mods of the basic prime number routine...I'd like to see something really unique.

Hey halsafar,

firstly this is a test contest so its nothing too hard (but still makes people think) just to get everyone into the flow and routine of the contests, i think you should take a look at the FAQ located at the top of this forum it tells you everything you need to know :) there are no major prizes, the contest is just fun coding where you can learn and hopefully win :) this contests' winner gets a custom name title :) and after speed some marks are awarded for the 'sexyness' and origionality of your code :)

Pino

NoteMe
Sep 12th, 2004, 02:16 PM
Originally posted by NotLKH
Hows .0455 Seconds, compiled, Avweraged over 11 loops, Clearing and Populating the listbox every loop, sound on a 400 mHz HP?

:wave:
-Lou

That sounds fast....can you mail me the compiled version so I can test it on my machine...???? Please?

NoteMe
Sep 12th, 2004, 02:20 PM
Originally posted by Merri
[B]First of all, I'd never touch .NET unless I'd need it in my job (and my current job isn't programming related ;)). So yeah, I'm doing it with pure VB6: no API, no type libraries, no assembler etc. With a listbox it takes the steady 5 ms to show 1000 primes in the listbox (9 ms in the IDE). I formatted my code so that if the people who time the codes want to, they can leave out the listbox.




What happend to the 1ms with showing the list box...did you cheat...;)

NotLKH
Sep 12th, 2004, 02:26 PM
Originally posted by NoteMe
That sounds fast....can you mail me the compiled version so I can test it on my machine...???? Please?
Sure.

Of course, it could be only my imagination.

Hmmm, How are you going to test it compiled, if you don't have access to the code, to throw in a timer?

Or would you like the compiled one with my timing event?

err, well, the looping timer event is done with the button labeled Command 1.

INCOMING!!!
:D

NoteMe
Sep 12th, 2004, 02:28 PM
INcomming? do you know my mail? Well send it to note(a)broadpark.no and yeah, add the timer too it...;) If not it won't help much...:)

NotLKH
Sep 12th, 2004, 02:29 PM
Originally posted by NoteMe
That sounds fast....can you mail me the compiled version so I can test it on my machine...???? Please?

Hmmm, can't seem to find your email button.
PM's don't allow attachements...

Ah well. I'll attach it.

:wave:

Let me know what you find!

-Lou

[EDITED: SEE BELOW]

NotLKH
Sep 12th, 2004, 02:32 PM
Originally posted by NoteMe
INcomming? do you know my mail? Well send it to note(a)broadpark.no and yeah, add the timer too it...;) If not it won't help much...:)
Ahh, well, assuming (a) means @, I've just sent it off.

Assuming you got it, then I'll go ahead and delete my attachment, above.

:wave:

NoteMe
Sep 12th, 2004, 02:40 PM
Hmmmm....very weird...I get 9.9ms every time...hmmm...well at least thats not bad even if it is weird it gives me the same time every time...still it is more then twice as slow as mine tho...;)

Merri
Sep 12th, 2004, 02:41 PM
Originally posted by NoteMe
What happend to the 1ms with showing the list box...did you cheat...;)

I never said I got 1 ms with a listbox ;) If you reference to the EXE I posted, it shows the timing before filling up the listbox.

Of course I can try to optimize the listbox filling too... :D

NotLKH
Sep 12th, 2004, 02:59 PM
Just curious,
I changed a couple of lines,
Whats the speed now?

:wave:
-Lou

NotLKH
Sep 12th, 2004, 03:15 PM
Heh!

I forgot about Properly titling my entry, ie...

"Contest 1 Prime Numbers - Electroman"

All better now!

:p
-Lou

wossname
Sep 12th, 2004, 05:13 PM
Originally posted by Merri
I never said I got 1 ms with a listbox ;) If you reference to the EXE I posted, it shows the timing before filling up the listbox.

Of course I can try to optimize the listbox filling too... :D



Aha! So us mere mortals do stand a slim chance after all!

:lol:

ph34r w055n@|\/|e, (and his sloppy coding style) :D

Merri
Sep 12th, 2004, 06:11 PM
...or maybe not. I figured out a new algorithm, at the moment if gives errorneus results, but if I manage to find a way to prevent the errors, it is awful fast: my current results for this new algorithm under IDE is 0,2 ms for 1000 and 6,3 ms for 32767. It will slow down though, atm I don't know how much. I just hope I can really get past the errors...


Edit Too bad, the speed is too slow with only 1000 items. I had to code sorting routine to fix the error and that ruined the speed. Now looking for alternative methods...

NoteMe
Sep 12th, 2004, 07:27 PM
Originally posted by NotLKH
Just curious,
I changed a couple of lines,
Whats the speed now?

:wave:
-Lou

Are you kidding with me...you must do. Well after first try I got 7.1ms...every time...no change at all...you must be kidding with me...well that is fast...but not fast enough....;)...but you have probably cuter code then me tho'.....:D

cyborg
Sep 12th, 2004, 07:46 PM
Cool! I just love contests! :)

Im down to ~10ms on my 1.9 GHz machine. :blush:

mendhak
Sep 12th, 2004, 07:52 PM
Damn... I forgot to do the
Contest 1 Prime Numbers - Mendhak thing.

Oy Electroman, go edit my thread and make the appropriate changes!

Electroman
Sep 12th, 2004, 08:43 PM
Posted by NotLKH
Heh!

I forgot about Properly titling my entry, ie...

"Contest 1 Prime Numbers - Electroman"

All better now!

:p
-Lou :lol:

Was wondering what was going on when i saw three posts by you :lol:



Mendhak: I hadn't actually noticed you'd used the title "All your prime numbers are belong to us" first of all, will edit it.... :lol:

Tec-Nico
Sep 13th, 2004, 01:00 AM
Hey guys, is this fast enough?

I am just taking in consideration the algorithm...

:wave:

http://www.vbforums.com/attachment.php?s=&postid=1785845

Deepak Sakpal
Sep 13th, 2004, 03:05 AM
yaba daba doo ;)

Deepak Sakpal
Sep 13th, 2004, 03:10 AM
r we allowed to hardcode values :confused: , like this:For iCtr = 2 To 7919
IsPrimeNo(iCtr)
Next

Deepak Sakpal
Sep 13th, 2004, 03:17 AM
my app displays 0.232493515237272. how many ms is this ?

mendhak
Sep 13th, 2004, 03:28 AM
Originally posted by Deepak Sakpal
my app displays 0.232493515237272. how many ms is this ?

Depends. How did you calculate it?

Deepak Sakpal
Sep 13th, 2004, 03:30 AM
i used sTime class provided by NoteMe

NoteMe
Sep 13th, 2004, 04:03 AM
Originally posted by Deepak Sakpal
my app displays 0.232493515237272. how many ms is this ?

232ms....;)

NoteMe
Sep 13th, 2004, 04:04 AM
Originally posted by Tec-Nico
Hey guys, is this fast enough?

I am just taking in consideration the algorithm...

:wave:

http://www.vbforums.com/attachment.php?s=&postid=1785845

I don't hope that is timed with the adding to the list box...then I am but ****ed. Even if it is not, it is still fast...;)

mendhak
Sep 13th, 2004, 04:42 AM
Originally posted by Electroman

Mendhak: I hadn't actually noticed you'd used the title "All your prime numbers are belong to us" first of all, will edit it.... :lol:

Did I really do that? :ehh:

NotLKH
Sep 13th, 2004, 06:07 AM
Originally posted by NoteMe
Are you kidding with me...you must do. Well after first try I got 7.1ms...every time...no change at all...you must be kidding with me...well that is fast...but not fast enough....;)...but you have probably cuter code then me tho'.....:D
Thought of a couple of more lines to tweak on they way home from work yesterday. Should bump it down to more acceptable standards.

Hey, It'd be interesting if they had preliminary results on the codes, to provide incentive for us to really max out our codes.

:wave:
-Lou

BodwadUK
Sep 13th, 2004, 06:55 AM
Think I have stuck to the rules

tends to be 0.03075 ms

Its VB6.0 btw

think its a 1400 Duron btw :)

BodwadUK
Sep 13th, 2004, 07:00 AM
Its very difficult to tell at these speeds because background processing affects the numbers dramatically even when you have no apps running

0.030375
0.031

etc

had it down to 0.01 something before but it was coincidence I think :D

cyborg
Sep 13th, 2004, 07:05 AM
Hey BudwadUK... Your program only does up to 1197.. The 1000nd prime is 7919.

BodwadUK
Sep 13th, 2004, 07:08 AM
poop

you sure :lol:

BodwadUK
Sep 13th, 2004, 07:35 AM
Oops I was fiddling with my code too much :cry:

BRB

cyborg
Sep 13th, 2004, 07:35 AM
Damn! I just found a stupid thing in my program that adds 2 ms...
Is it possible to send the improved version?

BodwadUK
Sep 13th, 2004, 07:37 AM
Can we make assumptions e.g do we HAVE to calculate by checking all numbers or can we skip them if mathmatically they cant be prime numbers :)

cyborg
Sep 13th, 2004, 07:39 AM
I think that's ok...
I don't check even numbers (except 2) because they can't be primes.

BodwadUK
Sep 13th, 2004, 07:41 AM
Could you check this for us :D

cyborg
Sep 13th, 2004, 07:44 AM
Is the timing in seconds? I get 0.15-0.17 compiled.

cyborg
Sep 13th, 2004, 07:47 AM
I get around 0.008s on my app, but on the one I sent in I get around 0.01s...

BodwadUK
Sep 13th, 2004, 07:53 AM
I did it originally like that and thought it would be classed as cheating because the system hadnt really worked it out :D

BodwadUK
Sep 13th, 2004, 07:56 AM
0.2 compiler duron 1400 or so :D

0.12 if i compile with advanced debugging options set :D

cyborg
Sep 13th, 2004, 08:02 AM
Yeah... Im down to 0.0074 with the advanced options on.

Merri
Sep 13th, 2004, 08:07 AM
Woohoo! I finally found out a superb routine! 0,03 ms compiled and 1,1 ms in IDE for 1000 primes. It gives correct results too! :D

Gotta download a better timing code, I had to use GetTickCount and loop the code 10000 times to get it accurate... worked out the whole thing on my laptop. I love modem :)


Edit 51 ms to find 41538 primes (all primes below 500000).

cyborg
Sep 13th, 2004, 08:09 AM
Get the sTime module... It's pretty accurate.

What machine are you running on?

Merri
Sep 13th, 2004, 08:25 AM
Athlon XP-M 2400+ @ 1800 MHz

Btw, the results went down when I switched to sTime. Happiness.

NotLKH
Sep 13th, 2004, 10:05 AM
Originally posted by BodwadUK
Can we make assumptions e.g do we HAVE to calculate by checking all numbers or can we skip them if mathmatically they cant be prime numbers :)
I use 2 as a hard coded prime.

a comment in my progie
'Also, since 1 is not a prime, and since the only whole positive integer below 2 is 1, then
'2 is the first prime


I've heard someone say they need the first 2 primes for their progie to work.

Some people, I expect, are sequencing with 6n Plus or Minus 1, which is an inherent usage of 2 and 3 as primes.

Obviously, the more primes you hard code, the faster your code will run.

Perhaps a point system should be applied, allowing you usage of n primes hard coded, but it lowers your overall for every one you use.

-Just a thought
-Lou

Electroman
Sep 13th, 2004, 11:03 AM
As for the hardcoded primes thing we decided you could hardcode as many as you wanted but be warned you will loose points for "sexiness" of the algo if you go over the top ;).

Electroman
Sep 13th, 2004, 11:04 AM
BTW Bodwad are you not entering your code? Just cos you're keep posting it publicly :confused:.

BodwadUK
Sep 13th, 2004, 11:17 AM
Is it still finishing on the 25th?

Dont we just post it here :confused:

Electroman
Sep 13th, 2004, 11:21 AM
:rolleyes:



I can only hope you are joking :lol:.

Pino
Sep 13th, 2004, 12:45 PM
Originally posted by BodwadUK
Is it still finishing on the 25th?

Dont we just post it here :confused:


you have to post your code in the contest entries forum :) otherwise people can steal your code :-(

http://vbforums.com/forumdisplay.php?s=&forumid=68

make a new thread and it will not be visible :)

Tec-Nico
Sep 13th, 2004, 02:31 PM
How strange nobody commented about my 0.000028495 seconds...

I made it on a Pentium II. :ehh:

Which is the minimum so far? Please show your times like the messagebox does or pass it to seconds like I did.

Greetings... :)

Tec-Nico
Sep 13th, 2004, 02:43 PM
Bodwad, use NoteMe's code (Platipus') to measure the time...

I think yours go around the 0.9 seconds and I believe you can do better than that.

ntg
Sep 13th, 2004, 03:11 PM
Originally posted by Merri
Woohoo! I finally found out a superb routine! 0,03 ms compiled and 1,1 ms in IDE for 1000 primes. It gives correct results too! :D


Well, mine was 0,5 ms when I posted...just figured a small improvement and it went down to 0,14 ms for debug configuration and 0,103 ms for release configuration (P4@2,4Ghz, 1GB RAM,W2K Prof,VS.NET 2002). But I think that that's the bottom line for me, I can't see how to squeeze that anymore. Out of curiosity Merri, what's the box you're running your code on ?

Cheers,
NTG

PS: OK. I got curious and wrote it for VB6. With optimizations, runtime gives me 0,076 ms on the same machine.

NoteMe
Sep 13th, 2004, 03:13 PM
Originally posted by Tec-Nico
How strange nobody commented about my 0.000028495 seconds...

I made it on a Pentium II. :ehh:

Which is the minimum so far? Please show your times like the messagebox does or pass it to seconds like I did.

Greetings... :)


How strange that you didn't notice that I commented it and even asked a question or two about it....;)

Merri
Sep 13th, 2004, 03:57 PM
Came to tell I dropped below Tec-Nico's reported value, though I have to admit I have a more powerful computer. As for the computer specs, I have told my both computers' specs a few times already, just scroll up ;)

My current result is 0,024 ms and 0,032 ms for the second algorithm. Yea, I have two and I'm working on both. The latter one is younger (just wrote it), so there is still stuff to optimize. I'm really encouraging people, am I not? :D

Edit My newer algorithm passes the older one with big primes: the more primes to count, the faster the new algorithm is in comparison. But I need to make it faster in shorter interval too!

ntg
Sep 13th, 2004, 04:20 PM
>>> But I think that that's the bottom line for me.
Me and my big mouth. :rolleyes: Sometimes I keep forgeting that the obvious things are always really hard to find. Saw a couple of things again and dropped to 0,06ms for release environment.

What troubles me, however, is something completely trivial that I really stumbled upon. I had a line of code:

While j < 7920 / 2

Innocent, right ? I figured that the compiler would know that this is a constant and substitute for the actual value of 3960. Built (always release env) and I get 0,085 ms. Changed the code to:

While j < 3960

Built again and I get 0,06 ms :eek: ! Geez, I don't know about other people but this came as a surprise to me. The compiler created different IL code for it. Still haven't figured it out completely but there's a conversion to float when I use 7920 / 2. OK, runtime doesn't have a way of knowing what the division will produce so it assumes float but hell, the compiler should figure out that 7920 / 2 is an integer and substitute it! When I changed the statement to While j < 7920 \ 2, I got 0,06 ms again.

Cheers,
NTG

Tec-Nico
Sep 13th, 2004, 04:23 PM
Yeah, NoteMe, I noticed so... But nobody else besides you made a comment about it.

I am working on a better algorithm to see if I can go below what I achieved.

Ex-FB
Sep 13th, 2004, 04:35 PM
Tsk! It's amazing what a warm bath and a cold beer will do for the thought processes. Okay, came up with a waaaaay simpler algorithm and got my time down to 0.6ms (or 0.027ms if I don't bother showing them)...... I might try .Net out for a laugh and see what I can do...

cyborg
Sep 13th, 2004, 04:39 PM
Originally posted by Ex-FB
0.6ms (or 0.027ms if I don't bother showing them)

So it takes about 0.6ms to show them? How?!
For me it takes like 3-4ms to show.

Merri
Sep 13th, 2004, 04:43 PM
I feel like spamming. Now at 0.020XXX ms. I'll be happy if I manage to get past 0.015 ms.

cyborg
Sep 13th, 2004, 04:48 PM
Damn! I can't wait to see how you did it!

ntg
Sep 13th, 2004, 06:00 PM
Originally posted by Merri
I feel like spamming. Now at 0.020XXX ms. I'll be happy if I manage to get past 0.015 ms.

:p lol. I'm looking forward to seeing your code Merri. I maxed out at 0,043 ms for VB.Net (0,0407 ms for VB6). That's enough contest fun for me for now. :wave:

Cheers,
NTG

manavo11
Sep 13th, 2004, 06:19 PM
I just hit 80ms... By changing 3 lines I got to 80 from 360... But I'm still far behind :(

Merri
Sep 13th, 2004, 06:44 PM
Submitted. I couldn't get it below 0,02 ms with the current algorithm, so I ended up sending it. I've spent far too much time on this.

manavo11
Sep 13th, 2004, 06:46 PM
Originally posted by manavo11
I just hit 80ms... By changing 3 lines I got to 80 from 360... But I'm still far behind :(

never mind... it went down so much cause it didn't work... I'm back at 360 :cool:

Edit: I got it better :) This time I'm at 110ms and working correctly :D On a PIII 500MHz 192 MB RAM. But I'm still at the end of the race :cry:

NotLKH
Sep 13th, 2004, 06:51 PM
Hmmm.
Decided to try a more traditional method than what I had.

On my 400 mhz, it averages to .01 seconds.

Without Listboxing, its .0055 seconds.

I guess I'll have to play with my listboxing some more.

-Lou

Ex-FB
Sep 13th, 2004, 07:59 PM
Yeah, I think I'm pretty much done here.... all I need to do now is make the code look "sexy"....

For the record (and to keep the spirit of competition going) I'm getting
0.3ms to calculate only
and
9ms to calculate and display listbox
on my old Athlon 600 with 64mb Ram

==============================

0.017ms to calculate only
and
0.74ms to calculate and display listbox
on my 1800+ (1.5 ghz) Athlon

================================

0.015ms to calculate only
and
0.6ms to calculate and display listbox
on my 2.4 Intel Celery-stick

==============================
(Guess my old Athlon's graphics card sucks)

Cheers.

EricDalnas
Sep 13th, 2004, 08:50 PM
I know I have no chance of winning, my only hopes in entering is to not come in last. That being the case will you display all the entries ranked by time?

Eric Dalnas

Electroman
Sep 13th, 2004, 09:02 PM
Yea, we'll show all entries ranked by Score, timing is not the only thing it will be judged on ;).

Electroman
Sep 14th, 2004, 09:33 AM
And Bodwad manages to get the title wrong :rolleyes:, not surprising after he was posting it everywhere else first of all :lol: :D.

BodwadUK
Sep 14th, 2004, 09:58 AM
:lol:

Its becuase I am supposed to be working so everthing is rushed :afrog:

EricDalnas
Sep 14th, 2004, 10:48 AM
Is it ok if we use the 1000th prime number in the code? that 7919 could come in handy.

NoteMe
Sep 14th, 2004, 10:49 AM
Originally posted by EricDalnas
Is it ok if we use the 1000th prime number in the code? that 7919 could come in handy.

Doesn't say no in the rules...;)

ntg
Sep 14th, 2004, 01:29 PM
Originally posted by EricDalnas
Is it ok if we use the 1000th prime number in the code? that 7919 could come in handy.

This is not a solution to a generalized problem, so I don't think that you would break any rules if you use 7919. After all, you can use prime theory to find that out without actually calculating all primes up to 7919. The scope of the contest is very limited so I wouldn't think that anybody would mind your using the number, unless of course Electroman says otherwise. If the contest was about calculating the first n primes (n entered by user and always larger than 1,000,000), that would be a different story, if you needed the last prime you would actually have to calculate it on the spot and it would affect your timing. But then again, in such a case I'm willing to bet that most of our algorithms would break or would be slower than 50,000,000 primes per second.

BTW, last accomplished time is 0,025 ms. This was entertaining, looking forward to see Merri's code and for the next contest.

Cheers,
NTG

mendhak
Sep 14th, 2004, 01:48 PM
Nobody has answered the timing issue for VB.NET apps yet. sTime should not be used. I'm suggesting the StopWatch class code from mentalis that I've posted earlier.

Tec-Nico
Sep 14th, 2004, 02:16 PM
What are you complaining about, mendhak?

I bet you are the only one doing it on VB .NET so you would win the contest in the VB .NET section :afrog:

That's if Electroman does not allow people posting their VB version and their VB .NET version.

Electroman
Sep 14th, 2004, 02:23 PM
Posted by Tec-Nico
That's if Electroman does not allow people posting their VB version and their VB .NET version. Only one or the other is allowed ;) :D.

As for the timing I'm not sure what is gonna be used for VB.NET as I don't think its either me or pino judging that. Could be brad but I'll look into it....

Pino
Sep 14th, 2004, 03:12 PM
Originally posted by ntg
This is not a solution to a generalized problem, so I don't think that you would break any rules if you use 7919. After all, you can use prime theory to find that out without actually calculating all primes up to 7919. The scope of the contest is very limited so I wouldn't think that anybody would mind your using the number, unless of course Electroman says otherwise. If the contest was about calculating the first n primes (n entered by user and always larger than 1,000,000), that would be a different story, if you needed the last prime you would actually have to calculate it on the spot and it would affect your timing. But then again, in such a case I'm willing to bet that most of our algorithms would break or would be slower than 50,000,000 primes per second.

BTW, last accomplished time is 0,025 ms. This was entertaining, looking forward to see Merri's code and for the next contest.

Cheers,
NTG

no its fine to inlclude that number, you could hard code ALL of the prime numbers and just display them, but your code wouldnt get many marks for sexynesss :) i think most people will be using one or two hard coded primes :)

wossname
Sep 14th, 2004, 03:47 PM
:stern tone of voice:

Now listen here electroman (sir)!

We, being expert professional coders and supergeeks, need to be reassured that the judges doing the timings are going to do a proper job. Not just some boy scout rubbing two sticks together. I too recommend the Mentalis.Stopwatch class.

Please inform us as to what is going to be done. [angry customer]If you don't know then please find out.[/angry customer] :D

Don't worry I still love you :lol:

mendhak
Sep 14th, 2004, 09:55 PM
AFAIK, just two people doing it in VB.NET: Me and wossname.

I'm really not sure why. I thought most of us would be doing it in VB.NET instead of VB6. I guess I guessed wrong. :p


Oh, and the Mentalis stopwatch class! Use it!

Merri
Sep 14th, 2004, 10:02 PM
That is because VB6 is so much better than VB.NET

And I guess VB6 still has the weight of being ranked as a slow language, so people are more likely to try to get to the edge of it :D

dsheller
Sep 14th, 2004, 10:27 PM
I wittled it down to 0.3ms (compiled) for the generation of the primes, how far that place me in the lineup heh =)

mendhak
Sep 15th, 2004, 12:57 AM
Originally posted by Merri
That is because VB6 is so much better than VB.NET


Let's save our boxing match for later, shall we ;)

Ex-FB
Sep 15th, 2004, 01:35 AM
In fairness, .Net does have a number of great features. But when it comes down to this sort of performance, JIT does suck the hind teet a bit compared to VB6. It's not such an issue in most jobs nowadays, but for a problem like this, it would seem prudent to go the VB6 root if you were comparing like for like.


Of course, they're not, so it doesn't really matter here... :p


* Waits for the fastest .Net solution to be faster than the fastest VB6 one... that learn me :p

BodwadUK
Sep 15th, 2004, 03:17 AM
So what timing method is going to be used in VB6? :confused:

ntg
Sep 15th, 2004, 03:53 AM
Originally posted by Ex-FB
In fairness, .Net does have a number of great features. But when it comes down to this sort of performance, JIT does suck the hind teet a bit compared to VB6. It's not such an issue in most jobs nowadays, but for a problem like this, it would seem prudent to go the VB6 root if you were comparing like for like.

Of course, they're not, so it doesn't really matter here... :p

* Waits for the fastest .Net solution to be faster than the fastest VB6 one... that learn me :p

To tell you the truth, I feel that if we're looking to such a limited problem and want to squeeze every last drop of performance, comparing VB.Net to VB6 doesn't make much sense. If it's that critical, C and ASM are the only viable options.

Regarding this little contest, I was curious and coded my algorithm in both VB.Net and VB6. VB6 actually came up 5% faster in the end and that's pretty marginal to me. Of course, I'm a bit biased towards business applications where this kind of speed improvements are easily counterbalanced by OOP features and a full-blown and coherent class library.

Don't get me wrong, I still love VB6 and I've used it for several projects in the past. But consider this: if the contest was to find the first 1,000,000 primes on a computer with hyperthreading, in VB.Net I'd spawn a couple of threads in three lines of code and split the calculation in half, something that I could never do in VB6 (or at least not without the use of a pricey external library or extensive arcane hacks).

Cheers,
NTG

Wokawidget
Sep 15th, 2004, 04:02 AM
You could do it in VB6 using the multithreading link in my sig :)

I was gonna enter, but I have been told there is much confusion regarding the marking, and couldn't be bothered getting dragged into a pointless argument :D

0.3ms Hmmmmmmmmmmmm
I am intregued on how you did that since adding 1000 0's to a listbox is WAY slower than that, and that's using API and hiding the listbox.

Wopof

NoteMe
Sep 15th, 2004, 04:09 AM
Originally posted by Wokawidget
You could do it in VB6 using the multithreading link in my sig :)

I was gonna enter, but I have been told there is much confusion regarding the marking, and couldn't be bothered getting dragged into a pointless argument :D

0.3ms Hmmmmmmmmmmmm
I am intregued on how you did that since adding 1000 0's to a listbox is WAY slower than that, and that's using API and hiding the listbox.

Wopof


Hmmm...he didn't say it was adding the nubers to the list box....;)

NoteMe
Sep 15th, 2004, 04:09 AM
Originally posted by BodwadUK
So what timing method is going to be used in VB6? :confused:

The sTimer class I posted....

Merri
Sep 15th, 2004, 04:15 AM
It makes no sense to time with listbox, because the time it takes to add items to listbox varies a lot. I even got bigger results most of the time for my faster algorithm with listbox, as weird as that sounds. I only optimized the algorithm, I didn't optimize initialization (because I wanted flexibility and the algorithm at top speed) and viewing of data (because I didn't want to code my own listbox... ;)).

The only problem with the algorithm I submitted is memory usage: it eats up a lot of memory. I couldn't get a memory saving version to time below 0,49 ms.

BodwadUK
Sep 15th, 2004, 04:26 AM
It takes almost no time at all to add to a listbox 1000 times :confused:


Dim t As Single
Dim I As Long

t = Timer

For I = 0 To 999
List1.AddItem I
Next I

Me.Caption = Timer - t


seems to come up with minus numbers most the time :eek:

NoteMe
Sep 15th, 2004, 04:59 AM
Not sure what that function is wrapped around, it doesn't say so in my old MSDN. But compiled with all the code on a form, with all the advanced optimization on that code you posted takes 14-15ms on my 1900+.


But I have also found out that the various implementations varies much on diffrent machines. Like the ones with a lot of branching P4 machines are getting realy big numbers, while they are doing great on older machines.


Like my code now does 3.7ms on my machine, 2.1ms on a 2.4Ghz, then 13MS on Electromans SUPER fast PC....so thats it for me....no more optimization for me....as long as I have no way to test it on the computer it will be tested on in the end, there is realy no way of telling when it is fast, and when it is not fast.....


I hate the 20 pipes on a P4....*grrrrrrr*

Wokawidget
Sep 15th, 2004, 05:03 AM
Damn...I was adding 10,000 numbers to my listbox :D

Bad Woka *SLAP*

BodwadUK
Sep 15th, 2004, 05:05 AM
:confused:


Oh well

*WHACK SLAP KICK*

Bad Woka get back in your set and dont come out until I say so. No dinner for you :mad:

NoteMe
Sep 15th, 2004, 05:09 AM
Originally posted by Wokawidget
Damn...I was adding 10,000 numbers to my listbox :D

Bad Woka *SLAP*


I told you that last time...don't you remember that? On MSN.....sick dog...sick dog...

riis
Sep 15th, 2004, 05:54 AM
I can't get the prime calculation below 15 ms on my 1.4 GHz laptop... :sigh: :(
The time including display them in the listbox is50 ms.

mendhak
Sep 15th, 2004, 06:24 AM
Originally posted by riis
I can't get the prime calculation below 15 ms on my 1.4 GHz laptop... :sigh: :(
The time including display them in the listbox is50 ms.

Change your algo.

NoteMe
Sep 15th, 2004, 06:49 AM
And set all the optimization you can....forget about the array boundary checks and so on....

wossname
Sep 15th, 2004, 07:15 AM
GET BACK TO WORK BODWAD!!

Noteme: what version of VB are you using?

NoteMe
Sep 15th, 2004, 07:43 AM
6.0....why?

ntg
Sep 15th, 2004, 08:07 AM
Originally posted by Wokawidget
You could do it in VB6 using the multithreading link in my sig :)
Wopof

Yeah, that's what I meant by "extensive arcane hacks". It's a great job you've done there, but it took you 8 months. It took me half that time to design, build, test and deploy a complete .Net business solution for a bank. That's what I'm talking about, all that time and energy could be spend more productively. Plus, I really don't know what would the results be if you were to actually measure performance of threading code powered by the .Net framework and threading code powered by your library. That's *not* a criticism towards your code, what I'm saying is that a lot of dev effort has gone into the framework and it's only natural to expect that it would be fine-tuned to the core.

Cheers,
NTG

Wokawidget
Sep 15th, 2004, 08:18 AM
Originally posted by ntg
Yeah, that's what I meant by "extensive arcane hacks". It's a great job you've done there, but it took you 8 months. It took me half that time to design, build, test and deploy a complete .Net business solution for a bank. That's what I'm talking about, all that time and energy could be spend more productively. Plus, I really don't know what would the results be if you were to actually measure performance of threading code powered by the .Net framework and threading code powered by your library. That's *not* a criticism towards your code, what I'm saying is that a lot of dev effort has gone into the framework and it's only natural to expect that it would be fine-tuned to the core.

Cheers,
NTG
I 100% agree with you :D

Merri
Sep 15th, 2004, 08:52 AM
NTG: But you forget that now we do have Woka's code here and we can more or less easily add it to our projects without the eight month delay if we need multithreading :D

When I happen to do bigger projects, I can use old code and other stuff I have done before, which basically gives me all the functionality and ease of coding VB.NET could give. Plus stuff .NET framework can't give me - of course it would be possible to recode the stuff for .NET, but that is what takes the time and effort.

But yeah, this goes a lot to personal preference. I like to use "good old stuff" until it is near useless. For example, I used C64 regularly until the end of 1997, even though I had had PC for two years or so. Why? I got VB4 and that finally took away the last reason to use C64 :)


Btw, I'm still looking for a faster algorithm :D

ntg
Sep 15th, 2004, 09:25 AM
Originally posted by Merri
NTG: But you forget that now we do have Woka's code here and we can more or less easily add it to our projects without the eight month delay if we need multithreading :D

When I happen to do bigger projects, I can use old code and other stuff I have done before, which basically gives me all the functionality and ease of coding VB.NET could give. Plus stuff .NET framework can't give me - of course it would be possible to recode the stuff for .NET, but that is what takes the time and effort.

But yeah, this goes a lot to personal preference. I like to use "good old stuff" until it is near useless. For example, I used C64 regularly until the end of 1997, even though I had had PC for two years or so. Why? I got VB4 and that finally took away the last reason to use C64 :)

Btw, I'm still looking for a faster algorithm :D
The last thing I want to be a part of is VB.Net vs VB6 forum war. Although I agree about reusability, my point about "arcane hacks" still applies. Yeah, you can use it but to do that you have to understand it and you have to code for using it. Take a long, hard look at what you need to do in order to comprehend and use that library (again, this is not a criticism of what I think is a nice piece of code). You end up putting a lot of effort to both understand and use it. The equivalent .Net approach is more simplistic, easier to learn and use. It's done away with the WinAPI and COM and that kind of stuff, that generally suck and/or are hard to master. Two months ago I hired a guy that had a solid programming background but extremely limited experience in .Net. Today, the same guy can enhance, modify and support 150k lines of code of both VB.Net and C#. With VB6, there was no way this could happen. And about functionality, we had to code for file I/O, DB operations, TCP/IP communications, remoting, web services, GUI interfaces, web interfaces, threading, sorting, merging, searching and plug-in DLL loading without once resorting to the WinAPI or an external component. That kind of power goes a long way. And, like it or not, support for VB6 and the old version of Studio is ultimately going to fade away for good - it would have already be entirely gone if it wasn't for the huge user base of the products. It's ok if you're a hobbyist (great actually, not just "ok"), but at some point in time it's going to be impossible to commercially develop in VB6 - it's already a construct that doesn't have strong enough foundations to support the plethora of additional features that seem to be attached to it using duct tape (see SOAP toolkit). At some point in time, saying that you develop commercially in VB6 is going to be today's equivalent of saying you're commercially developing in VB4. Existent, but tiny and shrinking market.

What you say about personal preference is true though. It was fun using the BBC and the C64 although it was a b*tch to wait for the tape ;) (boy, r we giving away our age). Myself, I used to be a Turbo Pascal fanatic until I gave it away when Windows killed DOS for good. I loved VB4/5/6 for several reasons, but for me it's time to move on. VB.Net is my current choice, other people choose something else whether it's C# or Java or Delphi or whatever, but it's definitely time to move.

riis
Sep 15th, 2004, 10:06 AM
Originally posted by NoteMe
And set all the optimization you can....forget about the array boundary checks and so on....
That only made a very slight difference.
Changing the algorithm might work, but this was just my first attempt, hacked in a moment while I was fed up with work.

NoteMe
Sep 15th, 2004, 10:26 AM
Originally posted by Merri
....Blah blah blah....


Originally posted by ntg
....Blah blah blah....


Very nice said...blah blah blah...but as I say to everyone that is arguing VB6 vs. VB.NET or VB vs C++ or something like that back and forth...."Finding the right tool for the job is the answer....not trying to fit a tool for a certain job"...

VB6 doesn't have answers to all our promlebs, and VB.NET doesn't have all the answers to our problems....end of discussion...:)

ntg
Sep 15th, 2004, 10:36 AM
Originally posted by NoteMe
Very nice said...blah blah blah...but as I say to everyone that is arguing VB6 vs. VB.NET or VB vs C++ or something like that back and forth...."Finding the right tool for the job is the answer....not trying to fit a tool for a certain job"...

VB6 doesn't have answers to all our promlebs, and VB.NET doesn't have all the answers to our problems....end of discussion...:)
Well said.:thumb:

BodwadUK
Sep 15th, 2004, 10:38 AM
Vb 6 solves more though :D

NoteMe
Sep 15th, 2004, 10:53 AM
Originally posted by ntg
Well said.:thumb:

Thanks..small kids do also have brains...:)...well I have the last 7 years twisted that quote around to fit what I belive in. It was the authour of my first VB book that gave me the quotes.

"Finding the right tool for the job"

and

"Don't reinvent the wheel"


Well guess he didn't make up those either....at least not the last one...:)

Pino
Sep 15th, 2004, 10:58 AM
http://www.vbforums.com/showthread.php?s=&postid=1788178#post1788178

Would be a better place to discuss these things :)

as for the contest, Your running out of time people get them entries in :)

and incase anyone is wondering we are working on making the next contest a bit more 'interesting'

NoteMe
Sep 15th, 2004, 11:04 AM
Can you give us any hints on the next one?

Pino
Sep 15th, 2004, 11:39 AM
heheh concentrate on this one first! the next one is top secret infomation

Tec-Nico
Sep 15th, 2004, 01:59 PM
Oh no! Electroman, Pino... :(

I was about to post mine... The deadline is today, isn't it?

Ex-FB
Sep 15th, 2004, 02:06 PM
The deadline is 10 days away... (25th September).

Pino
Sep 15th, 2004, 02:09 PM
Originally posted by Tec-Nico
Oh no! Electroman, Pino... :(

I was about to post mine... The deadline is today, isn't it?

Plenty of time yet :) 10 days left to perfect your code :)

Merri
Sep 15th, 2004, 02:09 PM
Ten days is soo long time to wait...

Btw, I noticed a small "bug" in my code, the one I posted: by removing two lines and adding their calculation into another line (two characters), the algorithm goes below 0.02 ms on both of my machines. Oh well.

Tec-Nico
Sep 15th, 2004, 03:10 PM
Thanks, Pino... :)

I hope I will get the best out of me for that day.

Hmmm.. Just a bit off topic (And out of curiosity) which was the avatar VisualAd used to have that made Brad say that? (What NoteMe is quoting)

Electroman
Sep 15th, 2004, 03:41 PM
Please notice that I have added an extra part to the rules which was overlooked at first (remember this is the first contest and we haven't fine tuned the process straight off).
If your entry doesn't meet this requirement then you will be able to resubmit the entry.

See here for the rules, the chnages have been highlighted like this.
http://www.vbforums.com/showthread.php?s=&action=showpost&postid=1782180


BTW work on the next contest is well underway and shouldn't need such changes like this as we plan to get the rules right before it goes live (expected date should be same day this one ends :)) ;).



Tec-Nico: his current one, the green blob :lol: :D.

riis
Sep 15th, 2004, 05:09 PM
Well guys, I've submitted my entry, have fun with it :D

Ex-FB
Sep 15th, 2004, 05:33 PM
Originally posted by Electroman
Please notice that I have added an extra part to the rules which was overlooked at first (remember this is the first contest and we haven't fine tuned the process straight off).
If your entry doesn't meet this requirement then you will be able to resubmit the entry.

See here for the rules, the chnages have been highlighted like this.
http://www.vbforums.com/showthread.php?s=&action=showpost&postid=1782180


BTW work on the next contest is well underway and shouldn't need such chnages like this as we plan to get the rules right before it goes live (expected date should be same day this one ends :)) ;).



Tec-Nico: his current one, the green blob :lol: :D.
:p Damn! I knew I shouldn't have sent my code in to the last minute......

But why change it, surely it's just another refinement to the coding. I managed to get my whole routine (including display) down the 0.6ms. I honestly think that was a fair enough way to optomise the code, and spent a fair bit of time working on it. :)

Isn't it a bit unfair to penalise my ingenuity :p

Electroman
Sep 15th, 2004, 05:45 PM
Posted by Ex-FB
:p Damn! I knew I shouldn't have sent my code in to the last minute......

But why change it, surely it's just another refinement to the coding. I managed to get my whole routine (including display) down the 0.6ms. I honestly think that was a fair enough way to optomise the code, and spent a fair bit of time working on it. :)

Isn't it a bit unfair to penalise my ingenuity :p I do think it was rather clever of you to think of that loop-hole. However it was kinda implied that we wanted one prime per entry and it was a mistake on our behalve to have not made it clear. Mind there is still 10 days left so that should be plenty, if this had only been noticed later on then we'd have let you off with it cos it wouldn't be fair on you to change the rules at the end of the contest :).

Ex-FB
Sep 15th, 2004, 05:59 PM
:) I don't really see it as a loop-hole as it is a valid way to tune an application. it's not just adding multiple entries per line, it's the way I build up the strings and the implement the scrolling etc.

When 90% of an applications speed is taken up by one bit of code, that's the major bit that should be tuned. That's what I did.

It's going to be difficult to judge the speed of the algo's when they are going to be so heavily outweighed by the listbox and you won't let us tune it.

I don't really mind, it is after all just a competition, but it does seem somewhat unfair and pointless, I'm not sure what your reasoning is (if it's just to make it easier to check the numbers, then it's easy for me to add an attachment that will spool them to a file... besides, I would have thought that rather than check all of them you would just check the winning entry and save yourself some time).

As an outsider joining this competition it just smacks a bit of changing the goal posts to suit the entries you have. I realise this is a test competition, and your still refining things, but isn't that all the more reason to be not to bothered about changing the rules to exclude someone's work.

Am I going to spend time working out another way of doing this only to find that you change the rules again to exclude me from winning?

Electroman
Sep 15th, 2004, 06:11 PM
I understand that really this problem shouldn't have been an issue in the first case if we'd put it in the rules from the start (I actually thought it was in the rules till a couple of days ago when I realised, I then querried others, competition runners, to see if we should add it) but as it was missed out we've had to make the decission.

It wasn't your entry that triggered this, as I stated in the other thread, but another member asked me whether it would be allowed. My first reaction was that the rules already said one per line and I then checked and saw it wasn't in. I then said well if it is allowed then it would loose points for appearance unless it was done very well with proper indenting or something like that. And as you can see after checking with others the change was made.

I suppose seen as though you feel so strongly and give good reasons then I do kind of regret it now, but taking it away now just means everyone will have the idea and then everyone will do it. Which I suppose would have been better just the odd one or two doing it.

Ex-FB
Sep 15th, 2004, 06:32 PM
Originally posted by Electroman
I understand that really this problem shouldn't have been an issue in the first case if we'd put it in the rules from the start (I actually thought it was in the rules till a couple of days ago when I realised, I then querried others, competition runners, to see if we should add it) but as it was missed out we've had to make the decission.

It wasn't your entry that triggered this, as I stated in the other thread, but another member asked me whether it would be allowed. My first reaction was that the rules already said one per line and I then checked and saw it wasn't in. I then said well if it is allowed then it would loose points for appearance unless it was done very well with proper indenting or something like that. And as you can see after checking with others the change was made.

I suppose seen as though you feel so strongly and give good reasons then I do kind of regret it now, but taking it away now just means everyone will have the idea and then everyone will do it. Which I suppose would have been better just the odd one or two doing it.

:p Don't worry, It doesn't really bother me too much. I'm guessing that maybe the person who asked you was one of the people who tested my executable :) Which is fine. It would make for a closer competition though if everyone did it (i.e. put more emphasis on the actual algorithm itself).

Whatever you decide is fine by me. :thumb:

Thanks for running the comp.

Merri
Sep 15th, 2004, 06:41 PM
This is also one of the major reasons I'd like atleast adding to listbox to be excluded from the timing. Without such hacks, there is no way making listbox any faster, and I myself preferred the individual selection of each item (for a reason, which you see when you happen to get your hands on my project). Instead of just speeding up I concentrated thoughts on the other areas too, I just didn't want to make a dull list of 1000 prime numbers.


Algorithm only: 0.02 ms
Algorithm and preparing memory: 0.03 ms
Algorithm and all initialization: 0.08 ms

All listbox stuff: 6.45 ms

Electroman
Sep 15th, 2004, 07:16 PM
Posted by Ex-FB
:p Don't worry, It doesn't really bother me too much. I'm guessing that maybe the person who asked you was one of the people who tested my executable :) Which is fine. It was yes but it wasn't in a spiteful way at all, they were actually checking to make sure you wouldn't get disqualified when it came to judging as that would have been rather bad.

I do agree that the listbox is a really big bottleneck and we should have either made them calculate more primes or just required you to fill in a array of ints/longs. The listbox was added to add an extra edge which would make you think about something that wasn't the algo. Yes I agree you did come up with a good thing but choice has been made on that. Also people shouldn't be just thinking about the speed there is other factors that will play a part in this too and as I see Ex-FB from your screen shot in the other thread you haven't ignored the appearance :).

For the next contest we are planning it in a way that means you will have the full scoring system from the beginning of the contest. Its not clear yet if the next one will be timed but if it is then we are going to avoid such bottlenecks or make the weighting of the time a low priority ;).

Ex-FB
Sep 15th, 2004, 07:36 PM
Originally posted by Electroman
It was yes but it wasn't in a spiteful way at all, they were actually checking to make sure you wouldn't get disqualified when it came to judging as that would have been rather bad.

Don't worry, I didn't for a second think it would have been spiteful :p This is a game, a fun mental challenge. I'd already mentioned it to a few people when they asked how i managed to get such an over-all fast time.

I also appreciate that it's very hard to know before you set the challenge as to how the solutions are going to work out, which makes your job of creating the marking method all the harder. I don't think there's going to be a measurable difference between all the top runners in this comp (we seem to be getting =<0.02ms calc times), but that would have been difficult for you to know before the comp.

But of course, that what this test comp was probably for, to iron out all these wrinkles, so in many ways you could say it's already been a resounding success :thumb: