|
Forum Index : Microcontroller and PC projects : Micromite trig functions cached?
| Author | Message | ||||
| factotum Newbie Joined: 29/10/2017 Location: United KingdomPosts: 18 |
I've been timing some Micromite Basic functions of mine that are very heavy on calling sin, cos, tan etc. I am surprised how fast they are. One function that calls a lot of trig functions only takes 42 ms at 10 MHz clock. Although I have made some effort to call them with a variety of different arguments within the timing loop, I just wondered if the trig library might contain some caching mechanism that remembers recently-requested argument values and returns the result quickly, rather than re-cacluating it from scratch. Anyone know? |
||||
| Paul_L Guru Joined: 03/03/2016 Location: United StatesPosts: 769 |
It's very simple to test it. t1=timer for j=1 to 100 for i=0.1 to 1.5 step 0.1 A=sin(i) '1500 calls to sin with different values next i next j t2=timer-t1:print t2 t3=timer for j=1 to 1500 A=sin(1) '1500 calls to sin with the same value next j t4=timer-t3:print t4 Paul in NY |
||||
| JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 4133 |
That might fail as a test. E.g. if some values take longer to calculate than others. Is reading the source code not an option? I think it's more a case of the CPU being fast :) John |
||||
| CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2171 |
I doubt it - that is a very broad broom with no real reason to expect you'd be wanting the same answer. I would imagine the transcendental functions are a product of the C compiler (and it's libraries) which most likely uses Polynomial functions to calculate the values. The time to cache and then search that cache is just too hit n miss, and wasted effort if a suitable match isn't found... just get down to the business of calculating the value. Polynomials of short sequences are very fast - I coded several in my early 20's to convert frequencies from a sonde receiver into real-life pressure, temperature & humidity values for PILOT/TEMP messages for the met office. Even on a 4MHz Z80 running interpreted basic they were over in the twinkle of an eye. |
||||
| Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3308 |
No, there is no caching. In MMBasic SIN(), TAN(), etc are just wrappers around floating point library functions provided by Microchip with their C compilers for the PIC32 family of chips. Microchip boast that these functions are carefully tuned for speed and they are fast. Another factor is the PIC32 chip with its MIPS processor core - it is very fast. In the 90's a number of million dollar minicomputers (Tandem, Pyramid) were built around the MIPS processor and now you can get the same technology in a $10 chip. The rate of change is amazing. Geoff Geoff Graham - http://geoffg.net |
||||
| factotum Newbie Joined: 29/10/2017 Location: United KingdomPosts: 18 |
Thanks for the above responses. Sorry I didn't get back sooner. |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |