summaryrefslogtreecommitdiff
path: root/README.benchmark.md
blob: 57293678cb613c9e01a62802329b0f63714e617b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Benchmark improvement  progress

## The initial benchmark timing based on v1.0-home-cooked-binary

~~~~
===== Execution time benchmark ======
     7.5 uS     empty function
 10983.6 uS     toBits(4000000)
   332.0 uS     toNum
   336.2 uS     freq2regestersValues
 96886.3 uS     copySettings
    37.2 uS     pad2NumBitsInPlace
  8796.9 uS     bitSlice
229184.0 uS     FreqToSettings
~~~~

## Skipping settings clone in FreqToSettings

Skipping the setting cloning via copySettings in FreqToSettings
shaved about 100 uS out of initial 230 uS. It is ok
to affect global workplace for settings since it is used
everywhere anyway.

~~~~
===== Execution time benchmark ======
     7.5 uS     empty function
  2785.8 uS     empty table creation
  4153.9 uS     table expand by 1 element
  5536.3 uS     table expand by 2 element
   146.1 uS     bit.rshift(4000000,1)
 10686.6 uS     toBits(4000000)
   331.9 uS     toNum
   333.4 uS     freq2regestersValues
 94721.6 uS     copySettings
    37.1 uS     pad2NumBitsInPlace
  8567.5 uS     bitSlice
123669.0 uS     FreqToSettings  <-- changed
~~~~


## toBits improvement with bitwise operation failed

Attempt to use bitmask and bitshifts  instead of calculating
reminder of division by 2 was unsuccessful. It increased
execution time from 10mS to about 15mS. I am guessing
that calling a function is longer then do division.
Binary representation table creation and expansion still
takes most of the time.

## Skipping table binary representation and working with bits directly

I abandoned a cleaner bits in tables approach, and use binary representation
of masks and appropriate bits from calculated settings. The code is much
harder to read but speed up of about 40 times totally worse it.

~~~~
> dofile("bench_lmx2487.lua")
===== Execution time benchmark ======
     8.2 uS     empty function
  2534.5 uS     empty table creation
  3768.0 uS     table expand by 1 element
  5032.4 uS     table expand by 2 element
   130.8 uS     bit.rshift(4000000,1)
   765.4 uS     microwire_send_data
   984.8 uS     send_register_lmx2487
   336.0 uS     freq2regestersValues
  2840.7 uS     FreqToSettings <-- changed
  5047.9 uS     setFreq
~~~~