Skip to content

Instantly share code, notes, and snippets.

@cfraizer
Last active June 4, 2020 16:17
Show Gist options
  • Save cfraizer/8f17c375837f6d904bcafd3adaa8466d to your computer and use it in GitHub Desktop.
Save cfraizer/8f17c375837f6d904bcafd3adaa8466d to your computer and use it in GitHub Desktop.
Compare "pure" Bash vs call to `tr`
#!/usr/bin/env bash
foo() {
local value="The Quick Brown FOX umped over The Lazy Dog."
local -i loopCount=1000
local -i i=0
for (( i = 0; i < loopCount; ++i )); do
local newVal=""
newVal="${value,,}"
printf "%s\n" "$newVal"
done
}
bar() {
local value="The Quick Brown FOX umped over The Lazy Dog."
local -i loopCount=1000
local -i i=0
for (( i = 0; i < loopCount; ++i )); do
# shellcheck disable=SC2155
local newVal=$(echo "$value" | tr '[:upper:]' '[:lower:]')
printf "%s\n" "$newVal"
done
}
baz() {
local value="$*"
printf "%s\n" "${value,,}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment