Skip to content

Commit

Permalink
Add fb package and an option to bench local file (#335)
Browse files Browse the repository at this point in the history
* Add fb package and an option to bench local file

* Move files to a dir; add year to license

* Move files to a dir; add year to license

* Fix lint
  • Loading branch information
kangax committed Dec 12, 2016
1 parent f1d2dc3 commit babb70c
Show file tree
Hide file tree
Showing 3 changed files with 216 additions and 8 deletions.
29 changes: 21 additions & 8 deletions scripts/benchmark.js
Expand Up @@ -20,15 +20,22 @@ let packagename, filename;
const script = new Command("benchmark.js")
.option("-o, --offline", "Only install package if not present; package not removed after testing")
.option("-r, --runs <n>", "Number of times to run tests")
.option("-l, --local", "Use local file instead of a package")
.usage("[options] <package> [file]")
.arguments("<package> [file]")
.action(function(pname, fname) {
packagename = pname;
filename = fname;
.action(function(pname, fname, command) {
if (command.local) {
packagename = "";
filename = pname;
}
else {
packagename = pname;
filename = fname;
}
})
.parse(process.argv);

if (!packagename) {
if (!packagename && !script.local) {
console.error("Error: No package specified");
process.exit(1);
}
Expand Down Expand Up @@ -91,8 +98,14 @@ function uninstallPackage() {
}

function checkFile() {
// If filename has not been passed as an argument, attempt to resolve file from package.json
filename = filename ? path.join(pathToScripts, "node_modules", filename) : require.resolve(packagename.split("@")[0]);

if (!script.local) {
// If filename has not been passed as an argument, attempt to resolve file from package.json
filename = filename
? path.join(pathToScripts, "node_modules", filename)
: require.resolve(packagename.split("@")[0]);
}

console.log("file: " + path.basename(filename));

if (!filename || !pathExists(filename)) {
Expand Down Expand Up @@ -224,14 +237,14 @@ function pathExists(path) {

const packagePath = path.join(pathToScripts, "node_modules", packagename);

if (!pathExists(packagePath) || !script.offline) {
if ((!pathExists(packagePath) || !script.offline) && !script.local) {
installPackage();
}

checkFile();
testFile();
processResults();

if (!script.offline) {
if (!script.offline && !script.local) {
uninstallPackage();
}
11 changes: 11 additions & 0 deletions scripts/benchmark_assets/LICENSE-examples
@@ -0,0 +1,11 @@
Copyright (c) 2008-present, Facebook, Inc. All rights reserved.

The examples provided by Facebook are for non-commercial testing and evaluation
purposes only. Facebook reserves all rights not expressly granted.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 comments on commit babb70c

Please sign in to comment.