Skip to content

Performance improvement suggestion: avoid calling hexWithoutQuotes when debug is not enabled #135

Description

@yewming-chen-sndk

hexWithoutQuotes function is always evaluated even when debug is not enabled especially for common write and _writeRead functions:

In a program that uses many i2c read/writes, hexWithoutQuotes + hex function can take over 2% of the runtime as shown in the following cProfile results:

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    15647  103.943    0.007  104.009    0.007 LabJackPython.py:374(_readFromExodriver)
    15647    5.683    0.000    5.770    0.000 LabJackPython.py:248(_writeToExodriver)
    56/51    3.911    0.070    3.911    0.077 {method 'acquire' of '_thread.lock' objects}
        9    1.826    0.203    1.826    0.203 {built-in method time.sleep}
    31287    1.534    0.000    2.471    0.000 LabJackPython.py:3182(hexWithoutQuotes)
  1182380    0.628    0.000    0.628    0.000 {built-in method builtins.hex}
    15640    0.367    0.000  114.058    0.007 LabJackPython.py:564(_writeRead)

Suggest adding a simple call guard to avoid hexWithoutQuotes getting evaluated when debug it not enable. For example:

        if self.debug:
            self._debugprint("Response: " + hexWithoutQuotes(result))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions