Search found 5320 matches

by dodicat
Dec 16, 2018 10:41
Forum: General
Topic: Squares
Replies: 6038
Views: 343694

Re: Squares

Hi Albert. I have only multiplied out the returned two ushorts. This is a simplified representation of the code. screen 19 do dim as ushort n1 = int(rnd*65536) dim as ushort n2 = int(rnd*65536) if n2 > n1 then swap n1 , n2 dim as string num1 = mkshort(n1) dim as string num2 = mkshort(n2) dim as ulon...
by dodicat
Dec 15, 2018 22:10
Forum: General
Topic: Squares
Replies: 6038
Views: 343694

Re: Squares

looks like you just have to multiply out (no easy shortcuts I can see) screen 19 do dim as ushort n1 = int(rnd*65536) dim as ushort n2 = int(rnd*65536) if n2 > n1 then swap n1 , n2 dim as string *2 num1 = chr(0)+chr(0) dim as ushort ptr usp1 = cptr( ushort ptr , strptr(num1) ) : *usp1 = n1 dim as st...
by dodicat
Dec 15, 2018 20:20
Forum: Tips and Tricks
Topic: Fast track an array of points.
Replies: 2
Views: 86

Re: Fast track an array of points.

Thanks TT
looks nice.
The travelling salesman problem
https://en.wikipedia.org/wiki/Travelling_salesman_problem#Exact_algorithms
seems a bit heavy and potential headache material, so mine is a quickie.
by dodicat
Dec 15, 2018 16:19
Forum: Tips and Tricks
Topic: Fast track an array of points.
Replies: 2
Views: 86

Fast track an array of points.

Re arrange an array of points to shorten the distance travelling between them. (Travelling salesman type algo) Type pt As Integer x,y End Type '===================== fast track ================ Type pts 'I would have put this udt inside the fasttrack sub, but alas not allowed. As pt p(Any) As Intege...
by dodicat
Dec 15, 2018 9:49
Forum: General
Topic: Which method better (faster)? Array of Strings or Ubytes?
Replies: 13
Views: 152

Re: Which method better (faster)? Array of Strings or Ubytes?

You also have wstrings to hold larger values (ushort). The access time is fast for string either way. (Don't use gcc optimisations to test) dim as long lim=100000000 dim as wstring * 1000 w w[500]=2018 dim as ushort s #print typeof( w[500]) dim as string g=string(lim,0) g[500]=200 dim as ubyte u dim...
by dodicat
Dec 15, 2018 9:12
Forum: General
Topic: Squares
Replies: 6038
Views: 343694

Re: Squares

Indeed Richard, I used the fb 64 bit compiler optimised -O3 for 22 seconds. The 32 bit optimised -O3 gets the answer in about one minute. I checked the results with gmp (only a few seconds), OK. Now, I daresay the team at gmp would would use optimisations along the way as they keep trying to get spe...
by dodicat
Dec 14, 2018 16:14
Forum: Tips and Tricks
Topic: Insert/Replace String procedures
Replies: 38
Views: 746

Re: Insert/Replace String procedures

A bit of fun before I move on. Using the replacer. Get a text file of a favourite writer into a folder, only need about 200 kb. Pop this code in the same folder and run it to get some data about the file in the form of triplets and a tally. if your language has some different combinations you can in...
by dodicat
Dec 14, 2018 15:11
Forum: Tips and Tricks
Topic: Insert/Replace String procedures
Replies: 38
Views: 746

Re: Insert/Replace String procedures

jj2007 If I use double indexed pointers in mine I get a little boost. but only with 64 bit optimized. Try with many replacements. marpon beats both of us in 32 bits with many replacements, and is very close with 64 bits. So these things are dependent on various factors including compiler and number ...
by dodicat
Dec 14, 2018 13:42
Forum: Tips and Tricks
Topic: Insert/Replace String procedures
Replies: 38
Views: 746

Re: Insert/Replace String procedures

I understand now marpon, you are talking about the sub with any.
The repeated sub is optimised out completely, but I would have thought with any used it would not be.
by dodicat
Dec 14, 2018 13:06
Forum: Tips and Tricks
Topic: Insert/Replace String procedures
Replies: 38
Views: 746

Re: Insert/Replace String procedures

marpon OK here O2 O3 none ... I get everybody's times Try an accumulator of timings for each method. ' #include "crt.bi" ' *** compile as 32- or 64-bit *** #INCLUDE ONCE "crt/string.bi" ' marpon #include "Windows.bi" Dim shared as zstring ptr retStr #define testfile &qu...
by dodicat
Dec 14, 2018 12:29
Forum: Tips and Tricks
Topic: Insert/Replace String procedures
Replies: 38
Views: 746

Re: Insert/Replace String procedures

marpon No, don't use any. I am saying fb automatically initialises to zero at a small overhead. But if you want to speed things up and you don't need an initial value then you could use any. sub tester dim as integer n=any ' try different things end sub dim as double t t=timer for n as long=1 to 100...
by dodicat
Dec 14, 2018 10:48
Forum: Tips and Tricks
Topic: Insert/Replace String procedures
Replies: 38
Views: 746

Re: Insert/Replace String procedures

Freebasic initialises to zero for a float, with a small overhead.
You can initialise to any with a smaller overhead.
dim as integer n=any
by dodicat
Dec 14, 2018 10:38
Forum: General
Topic: Fixed Length String handling
Replies: 39
Views: 567

Re: Fixed Length String handling

Indeed, sorry folks, chr(0) is not captured at all.
by dodicat
Dec 14, 2018 10:33
Forum: Tips and Tricks
Topic: Insert/Replace String procedures
Replies: 38
Views: 746

Re: Insert/Replace String procedures

In -gen gcc, while loop and do loop both are parsed to a goto label for the gcc compiler, so it shouldn't matter. jj2007 Normally for 64 bits I use longs, but actually integers are faster (although 4 bytes longer). The long return in Tally I forgot to change to integer, but it doesn't matter anyway....
by dodicat
Dec 14, 2018 10:23
Forum: General
Topic: Squares
Replies: 6038
Views: 343694

Re: Squares

Albert's tester. function mul_loop_7( num1 as string , num2 as string ) as string dim as string number1 = num1 dim as string number2 = num2 'make numbers equal multiple of 7 bytes dim as string str1 dim as longint dec1 do str1 = str(len(number1)/7) dec1 = instr(1,str1,".") if dec1 <> 0 the...

Go to advanced search