Post Reply 
Varying speed of a program.
05-25-2022, 03:51 PM (This post was last modified: 05-25-2022 04:09 PM by Albert Chan.)
Post: #10
RE: Varying speed of a program.
To speed up, we could do in-place divide, instead of building up quotient, 1 char at a time.

This eliminated cost of generating intermediate strings, and cost of garbage collection, both O(n^2)
(Timing jitters likely comes from unpredictable timing of garbage collection.)

With positive integer divisor, dividend has enough room to hold the quotient.

CAS> s := "12345"
CAS> s[1] =< "0"    // in-place string update
CAS> s                   → "02345"

s is treated just like an array, with INPUT showed array_sto("0",s[1])

Instead of removing quotient leading zeroes, we could track index of first non-zero entry.

Comment: we might as well work with true array, saving cost of str/num conversions.

HOME> L1 := ASC("12345") - 48      → {1,2,3,4,5}
HOME> L1[1] := 0                           → {0,2,3,4,5}
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Varying speed of a program. - matalog - 05-21-2022, 09:46 AM
RE: Varying speed of a program. - albud44 - 05-21-2022, 10:02 AM
RE: Varying speed of a program. - Gene - 05-21-2022, 10:09 PM
RE: Varying speed of a program. - matalog - 05-21-2022, 05:01 PM
RE: Varying speed of a program. - matalog - 05-21-2022, 11:47 PM
RE: Varying speed of a program. - anyfoo - 05-22-2022, 01:34 AM
RE: Varying speed of a program. - matalog - 05-24-2022, 08:43 PM
RE: Varying speed of a program. - Albert Chan - 05-25-2022 03:51 PM



User(s) browsing this thread: 1 Guest(s)