Last active
January 23, 2018 11:26
-
-
Save comm1x/d11ab5fabbb6c0526e14459d02fe5588 to your computer and use it in GitHub Desktop.
Script parse macbench site and print in one line in CLI
This file contains 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
#!/bin/bash | |
# brew install gnu-sed | |
# brew install html-xml-utils | |
if [ $# -eq 0 ]; then | |
echo "Mac Benchmark CLI interface" | |
echo "Usage: bench.sh MODE" | |
echo " 's' mode for single core" | |
echo " 'm' mode for multi core" | |
exit 0 | |
fi | |
PAGE=1 | |
if [ "$1" == "m" ]; then | |
PAGE=2 | |
fi | |
OUT=$( | |
curl -s "https://browser.geekbench.com/mac-benchmarks" \ | |
| hxnormalize -x \ | |
| hxselect ".tab-pane#${PAGE} table.mac-benchmark tbody" \ | |
| hxpipe \ | |
| grep '^-' \ | |
| hxunpipe \ | |
| gsed 's/^ *//' \ | |
| tr '\n' ' ' \ | |
| gsed 's/ */ /g' \ | |
| gsed -r "s/ Mac/\nMac/g" \ | |
| gsed -r "s/ iMac/\niMac/g" \ | |
| gsed -r "s/ Xserve/\nXserve/g" \ | |
| gsed "s/ //g" \ | |
| gsed "s/cores) /cores) /g" \ | |
| grep -v '^$' | |
) | |
echo "$OUT" | php -r ' | |
$file = fopen("php://stdin", "r"); | |
$regex = "/(?P<name>^.+) Intel (?P<cpum>.+) @ (?P<cpuf>.+) \((?P<cores>.+)\) (?P<score>\d+)/"; | |
while ($line = fgets($file)) { | |
preg_match($regex, $line, $m); | |
printf("%-42s Intel %-21s %-10s %-11s %5s\n", $m["name"], $m["cpum"], $m["cpuf"], $m["cores"], $m["score"]); | |
}' |
Author
comm1x
commented
Jan 22, 2018
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment