Skip to content
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

[keras/benchmarks/benchmark_util.py] Use var rather than string literal for is None checks on measure_performance #17980

Merged

Conversation

SamuelMarks
Copy link
Contributor

Found by running pydocstyle on entire codebase.

…al for `is None` checks on `measure_performance`
@gbaned gbaned requested a review from haifeng-jin April 17, 2023 05:37
@google-ml-butler google-ml-butler bot added the keras-team-review-pending Pending review by a Keras team member. label Apr 17, 2023
raise ValueError("Input data is required.")
if "optimizer" is None:
elif optimizer is None:
Copy link
Contributor

@Frightera Frightera Apr 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @SamuelMarks,

Just curiosity, why did you switch into elif instead of if? I think keeping them independent might be a better practice, i.e maintain the if statements.

P.S: Don't take this as an official-review.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Frightera Because it's more efficient:

$ python -m timeit 'a="foo"' 'if a == "foo":' '   a += "bar"' 'if a == "can":' '   a += "can"'
5000000 loops, best of 5: 51.9 nsec per loop
$ python -m timeit 'a="foo"' 'if a == "foo":' '   a += "bar"' 'elif a == "can":' '   a += "can"'
10000000 loops, best of 5: 39.6 nsec per loop

Also it's more logical. The compiler probably optimises the branches better, and it's clearer to read.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think the speed difference is because of every if statement is executed in your example whereas in here there are ValueErrors which will cause not to execute other statements, probably the performance difference will be negligible.

Copy link
Member

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Apr 21, 2023
@fchollet fchollet removed the keras-team-review-pending Pending review by a Keras team member. label Apr 21, 2023
Copy link
Contributor

@haifeng-jin haifeng-jin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

copybara-service bot pushed a commit that referenced this pull request Apr 21, 2023
…tring literal for `is None` checks on `measure_performance`

Imported from GitHub PR #17980

Found by running `pydocstyle` on entire codebase.
Copybara import of the project:

--
f7de756 by Samuel Marks <[email protected]>:

[keras/benchmarks/benchmark_util.py] Use var rather than string literal for `is None` checks on `measure_performance`

Merging this change closes #17980

FUTURE_COPYBARA_INTEGRATE_REVIEW=#17980 from SamuelMarks:benchmark_util-is-check f7de756
PiperOrigin-RevId: 526075166
copybara-service bot pushed a commit that referenced this pull request Apr 21, 2023
…tring literal for `is None` checks on `measure_performance`

Imported from GitHub PR #17980

Found by running `pydocstyle` on entire codebase.
Copybara import of the project:

--
f7de756 by Samuel Marks <[email protected]>:

[keras/benchmarks/benchmark_util.py] Use var rather than string literal for `is None` checks on `measure_performance`

Merging this change closes #17980

FUTURE_COPYBARA_INTEGRATE_REVIEW=#17980 from SamuelMarks:benchmark_util-is-check f7de756
PiperOrigin-RevId: 526075166
@gbaned gbaned added ready to pull Ready to be merged into the codebase and removed ready to pull Ready to be merged into the codebase labels May 9, 2023
copybara-service bot pushed a commit that referenced this pull request May 16, 2023
…tring literal for `is None` checks on `measure_performance`

Imported from GitHub PR #17980

Found by running `pydocstyle` on entire codebase.
Copybara import of the project:

--
f7de756 by Samuel Marks <[email protected]>:

[keras/benchmarks/benchmark_util.py] Use var rather than string literal for `is None` checks on `measure_performance`

Merging this change closes #17980

FUTURE_COPYBARA_INTEGRATE_REVIEW=#17980 from SamuelMarks:benchmark_util-is-check f7de756
PiperOrigin-RevId: 530510171
@copybara-service copybara-service bot merged commit 55d0331 into keras-team:master May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to pull Ready to be merged into the codebase size:XS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants