[PR #59] [MERGED] Use 1 << exp instead of Math.Pow(2, exp) #97

Open
opened 2026-01-30 21:27:06 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/claunia/plist-cil/pull/59
Author: @qmfrederik
Created: 6/12/2019
Status: Merged
Merged: 6/12/2019
Merged by: @claunia

Base: masterHead: fixes/math-pow


📝 Commits (1)

  • 40dbb46 Use 1 << exp instead of Math.Pow(2, exp)

📊 Changes

1 file changed (+3 additions, -3 deletions)

View changed files

📝 plist-cil/BinaryPropertyListParser.cs (+3 -3)

📄 Description

Math.Pow(double, double) is a relatively expensive operation (since it can take an arbitrary exponent). For powers of two, byteshift operators are much faster.

Benchmark.NET can't actually measure the time it takes to do 1 << exp, but Math.Pow(2, exp) takes about 40 nanoseconds. It was actually slow enough to show up in some of the performance traces we took.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/claunia/plist-cil/pull/59 **Author:** [@qmfrederik](https://github.com/qmfrederik) **Created:** 6/12/2019 **Status:** ✅ Merged **Merged:** 6/12/2019 **Merged by:** [@claunia](https://github.com/claunia) **Base:** `master` ← **Head:** `fixes/math-pow` --- ### 📝 Commits (1) - [`40dbb46`](https://github.com/claunia/plist-cil/commit/40dbb464a3fdacfa40ec38d3c98d9c6271cceee1) Use 1 << exp instead of Math.Pow(2, exp) ### 📊 Changes **1 file changed** (+3 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `plist-cil/BinaryPropertyListParser.cs` (+3 -3) </details> ### 📄 Description `Math.Pow(double, double)` is a relatively expensive operation (since it can take an arbitrary exponent). For powers of two, byteshift operators are much faster. Benchmark.NET can't actually measure the time it takes to do `1 << exp`, but `Math.Pow(2, exp)` takes about 40 nanoseconds. It was actually slow enough to show up in some of the performance traces we took. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-30 21:27:06 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: claunia/plist-cil#97