This version with the string in memory, no error checking, and using a variable, seems simplest to me.
variable p
: advance ( -- ) 1 p +! ;
: digit ( -- n ) p @ c@ '0' - advance ;
: 2digit ( -- n ) digit 10 * digit + ;
: hms ( a u -- h m s ) drop p !
2digit advance 2digit advance 2digit advance ;
This version with the string in memory, no error checking, and using a variable, seems simplest to me.
variable p
: advance ( -- ) 1 p +! ;
: digit ( -- n ) p @ c@ '0' - advance ;
: 2digit ( -- n ) digit 10 * digit + ;
: hms ( a u -- h m s ) drop p !
2digit advance 2digit advance 2digit advance ;
: test clearstack s" 12:34:56" hms ;
test .s
This version with the string in memory, no error checking, and using a variable, seems simplest to me.
variable p
: advance ( -- ) 1 p +! ;
: digit ( -- n ) p @ c@ '0' - advance ;
: 2digit ( -- n ) digit 10 * digit + ;
: hms ( a u -- h m s ) drop p !
2digit advance 2digit advance 2digit advance ;
: test clearstack s" 12:34:56" hms ;
test .s
: hms ( a u -- h m s ) drop p !^^^^^^^
2digit advance 2digit advance 2digit advance ;
: hms ( a u -- h m s ) drop p !This serves no purpose.
2digit advance 2digit advance 2digit advance ;
This version with the string in memory, no error checking, and using a variable, seems simplest to me.
variable p
: advance ( -- ) 1 p +! ;
: digit ( -- n ) p @ c@ '0' - advance ;
: 2digit ( -- n ) digit 10 * digit + ;
: hms ( a u -- h m s ) drop p !
2digit advance 2digit advance 2digit advance ;
: test clearstack s" 12:34:56" hms ;
test .s
It doesn't do the same thing. It isn't faster, which points out
the '60 *' and 'M* D+' are not the limiting factors.
mhx@iae.nl (mhx) writes:
It doesn't do the same thing. It isn't faster, which points out
the '60 *' and 'M* D+' are not the limiting factors.
Oh I copied the interface from another post, didn't realize it was
supposed to convert to seconds. I didn't care about the speed since any slowness in any of these versions can be blamed on the compiler ;).
Here is another version:
variable p
: advance 1 p +! ;
: digit ( -- n ) p @ c@ '0' - advance ;
: 2digit ( -- n ) digit 10 * digit + advance ; \ skips trailing colon
: hms ( a u -- n ) drop p ! 2digit 60 * 2digit + 60 * 2digit + ;
: test clearstack s" 12:34:56" hms ;
test .s
iSPICE> TEST TEST TEST TEST
\ dtimescan : 2515 clock ticks elapsed, 45296
\ timestrscan : 419 clock ticks elapsed, 45296
\ HMS : 419 clock ticks elapsed, 45296
It makes no difference. Whatever is holding it down must
be quite severe.
This version with the string in memory, no error checking, and using a variable, seems simplest to me.
variable p
: advance ( -- ) 1 p +! ;
: digit ( -- n ) p @ c@ '0' - advance ;
: 2digit ( -- n ) digit 10 * digit + ;
: hms ( a u -- h m s ) drop p !
2digit advance 2digit advance 2digit advance ;
: test clearstack s" 12:34:56" hms ;
test .s
mhx@iae.nl (mhx) writes:
iSPICE> TEST TEST TEST TEST
\ dtimescan : 2515 clock ticks elapsed, 45296
\ timestrscan : 419 clock ticks elapsed, 45296
\ HMS : 419 clock ticks elapsed, 45296
It makes no difference. Whatever is holding it down must
be quite severe.
Is dtimescan the one that uses double word arithmetic for 16 bit
processors? It's doing more stuff, I would think. Weird that it
catches up after a few tries. Cache warming?
Paul Rubin wrote:
This version with the string in memory, no error checking, and using a
variable, seems simplest to me.
variable p
: advance ( -- ) 1 p +! ;
: digit ( -- n ) p @ c@ '0' - advance ;
: 2digit ( -- n ) digit 10 * digit + ;
: hms ( a u -- h m s ) drop p !
2digit advance 2digit advance 2digit advance ;
: test clearstack s" 12:34:56" hms ;
test .s
: keep { lo hi adr len } lo adr len ;
: get { adr len } 0. adr len >number keep 1 /string ;
: hms ( adr len -- h m s) get get get 2drop ;
: test clearstack s" 12:34:56" hms ;
test .s
That's why I consider the use of global variables in library functions
worse than locals. You're polluting the namespace.
HMS is three times faster than dtimescan and timestrscan, while
HMS2 is 3.5 times slower (as expected).
mhx@iae.nl (mhx) writes:
HMS is three times faster than dtimescan and timestrscan, while
HMS2 is 3.5 times slower (as expected).
Is HMS the one that I posted, and HMS2 the version that's almost the
same? Why the speed difference: just because of the extra memory
traffic of leaving extra things on the stack?
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 503 |
Nodes: | 16 (3 / 13) |
Uptime: | 222:56:35 |
Calls: | 9,880 |
Calls today: | 2 |
Files: | 13,791 |
Messages: | 6,206,180 |
Posted today: | 1 |