Skip to content

Speed and size improvement in Print::printFloat() #4667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2016

Conversation

bblanchon
Copy link
Contributor

Avoid using the overload of print() for signed integer since a negative value is not allowed here.
This results in a smaller (unless print(int) is used somewhere else in the program) and faster code because the overload for unsigned integer is simpler.

Avoid using the overload of print() for signed integer since a negative value is not allowed here.
This results in a smaller (unless print(int) is used somewhere else in the program) and faster code because the overload for unsigned integer is simpler.
@bblanchon
Copy link
Contributor Author

Please merge this PR 🙏
It just change two words in one file.
It'll take 2 seconds to review, literally.

@proppy
Copy link

proppy commented Apr 27, 2016

friendly @cmaglie ping

@sandeepmistry
Copy link
Contributor

I just tested this with the following test sketch on an Uno:

void setup() {
  Serial.begin(9600);
  while(!Serial);

  uint32_t start = millis();
  for (int i = 0; i < 100; i++) {
    Serial.println(PI);
  }
  uint32_t end = millis();

  Serial.println(end - start);
}
void loop() {
}

Here are some metrics:

  • Without patch:
    • Sketch size 3,824 bytes
    • Execution time 556 ms
  • With patch:
  • Sketch size 3,644 bytes
  • Execution time 556 ms

sandeepmistry added a commit to sandeepmistry/Arduino that referenced this pull request Jul 18, 2016
Speed and size improvement in Print::printFloat()
sandeepmistry added a commit to sandeepmistry/Arduino that referenced this pull request Jul 18, 2016
@sandeepmistry sandeepmistry merged commit 9509587 into arduino:master Jul 18, 2016
sandeepmistry added a commit to sandeepmistry/ArduinoCore-samd that referenced this pull request Jul 18, 2016
@sandeepmistry
Copy link
Contributor

@bblanchon thanks!

I've also ported this change to the SAM (05be7ce) and SAMD (arduino/ArduinoCore-samd@94d6f56) cores.

More notes on size reduction for test sketch above:

  • Due
    • Before: 25,212 bytes
    • After: 25,068 bytes
  • MKR1000:
    • Before: 16,256 bytes
    • After: 16,088 bytes

Execution times were negligible.

@cmaglie cmaglie added this to the Release 1.6.10 milestone Jul 18, 2016
ollie1400 pushed a commit to ollie1400/Arduino that referenced this pull request May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants