makefiles/utils: functions for lowercase and uppercase#12119
Merged
jcarrano merged 1 commit intoRIOT-OS:masterfrom Aug 29, 2019
Merged
makefiles/utils: functions for lowercase and uppercase#12119jcarrano merged 1 commit intoRIOT-OS:masterfrom
jcarrano merged 1 commit intoRIOT-OS:masterfrom
Conversation
Add make only function to convert strings to lowercase and uppercase. This can replace the `$(shell echo $(var) | tr 'a-z-' 'A-Z_')` pattern. Using the 'make' implementation results in being around 100 times faster.
2b999f5 to
765f3e9
Compare
Contributor
Author
|
I miss-clicked "create pull request" before it was ready. Now the description and commit are up to date. |
Contributor
you are the man |
Contributor
Author
How could it be otherwise ? :D |
jcarrano
added a commit
to jcarrano/RIOT
that referenced
this pull request
Aug 29, 2019
Add functions to convert to lowercase/uppercase and another one that also replaces dashes for underscores. This is a remake of a PR by @cladmi (pr RIOT-OS#12119) The Make version is about 20 times faster than using the shell. The following patch can be used for testing (run make --no-print-directory -C examples/hello-world/ clean) diff --git a/examples/hello-world/Makefile b/examples/hello-world/Makefile index 258d8e9..1f2adf837 100644 --- a/examples/hello-world/Makefile +++ b/examples/hello-world/Makefile @@ -16,3 +16,5 @@ DEVELHELP ?= 1 QUIET ?= 1 include $(RIOTBASE)/Makefile.include + +include $(RIOTMAKE)/utils/strings.mk diff --git a/makefiles/utils/strings.mk b/makefiles/utils/strings.mk index c571cd6..7dce7d80d 100644 --- a/makefiles/utils/strings.mk +++ b/makefiles/utils/strings.mk @@ -39,3 +39,28 @@ lowercase = $(call xlate,$(_UPPER_LETTERS),$(_LOWER_LETTERS),$(1)) uppercase = $(call xlate,$(_LOWER_LETTERS),$(_UPPER_LETTERS),$(1)) uppercase_and_underscore = $(call uppercase,$(subst -,_,$1)) + + +#~ # Local testing +#~ var = abcdefghijklmnopqrstuvwxyz-123456789 +#~ VAR = ABCDEFGHIJKLMNOPQRSTUVWXYZ_123456789 + +#~ ifneq ($(call uppercase_and_underscore,$(var)),$(VAR)) + #~ $(error $(call uppercase_and_underscore,$(var))) +#~ endif + +#~ NUM ?= 10000 +#~ iters := $(shell seq $(NUM)) + +#~ d_0 := $(shell date +%s.%N) +#~ a := $(foreach i,$(iters),$(call uppercase_and_underscore,$(var))) +#~ d_end := $(shell date +%s.%N) +#~ d_diff := $(shell echo $(d_end) - $(d_0) | bc) +#~ $(warning makefile $(d_diff): $(d_0) - $(d_end)) + +#~ d_0 := $(shell date +%s.%N) +#~ $(foreach i,$(iters),$(shell echo $(var)| tr 'a-z-' 'A-Z_'>/dev/null)) +#~ d_end := $(shell date +%s.%N) + +#~ d_diff := $(shell echo $(d_end) - $(d_0) | bc) +#~ $(warning shell $(d_diff): $(d_0) - $(d_end))
Contributor
|
Check out jcarrano@620f031 the implementation there is slower but cleaner. |
Contributor
Author
|
With our current need, there is not need for a generic function I think. |
Contributor
Author
|
Thank you for the review. I will do PRs to start using it. |
This was referenced Sep 30, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contribution description
Add make only function to convert strings to lowercase and uppercase.
This can replace the
$(shell echo $(var) | tr 'a-z-' 'A-Z_')pattern.Using the 'make' implementation results in being around 100 times faster.
I was inspired by wondering how faster was the
lcimplementation inmips.inc.mk.RIOT/makefiles/arch/mips.inc.mk
Line 7 in e9ea6a0
Testing procedure
Running the test in
tests/build_system_utilsshould work.If you want to verify the test tests, you can also play with changing the functions implementation and replacing some characters.
Speed comparison.
I used this diff to compare the speed.
diff to get speed comparison
I also ran it with
NUM=100000to get a better average.It got sometime from 80 to 150 times faster depending on local load.
Issues/PRs references
This work is done in the context of removing immediate variable evaluations and exports
#10850
As when changing a variable from immediate to deferred, a
shellcall would be made at each evaluation. So better fix this first.