From 912e4f717785e2f5266d749c54a289227523db12 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 11 Jun 2019 14:38:19 -0400 Subject: feat: default output filename for deno bundle (#2484) And improve bundle docs --- .gitignore | 1 + cli/flags.rs | 37 +++++- js/unit_tests.ts | 2 +- tools/build_website.py | 8 ++ tools/upload_website.py | 6 +- website/app.js | 274 -------------------------------------------- website/app.ts | 299 ++++++++++++++++++++++++++++++++++++++++++++++++ website/app_test.js | 193 ------------------------------- website/app_test.ts | 196 +++++++++++++++++++++++++++++++ website/benchmarks.html | 30 +---- website/manual.md | 66 +++++++---- 11 files changed, 591 insertions(+), 521 deletions(-) create mode 100755 tools/build_website.py delete mode 100644 website/app.js create mode 100644 website/app.ts delete mode 100644 website/app_test.js create mode 100644 website/app_test.ts diff --git a/.gitignore b/.gitignore index 0dd8e57e4..5c16b784d 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ node_modules # temp benchmark data /website/data.json /website/recent.json +/website/*.bundle.js /js/gen diff --git a/cli/flags.rs b/cli/flags.rs index fa86df594..41d3f9308 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -186,11 +186,14 @@ compiler.", .setting(AppSettings::DisableVersion) .about("Bundle module and dependencies into single file") .long_about( - "Fetch, compile, and output to a single file a module and its dependencies. -" + "Output a single JavaScript file with all dependencies + +Example: + + deno bundle https://deno.land/std/examples/colors.ts" ) .arg(Arg::with_name("source_file").takes_value(true).required(true)) - .arg(Arg::with_name("out_file").takes_value(true).required(true)), + .arg(Arg::with_name("out_file").takes_value(true).required(false)), ).subcommand( SubCommand::with_name("fetch") .setting(AppSettings::DisableVersion) @@ -498,6 +501,29 @@ pub enum DenoSubcommand { Xeval, } +fn get_default_bundle_filename(source_file: &str) -> String { + use crate::worker::root_specifier_to_url; + let url = root_specifier_to_url(source_file).unwrap(); + let path_segments = url.path_segments().unwrap(); + let last = path_segments.last().unwrap(); + String::from(last.trim_end_matches(".ts").trim_end_matches(".js")) + + ".bundle.js" +} + +#[test] +fn test_get_default_bundle_filename() { + assert_eq!(get_default_bundle_filename("blah.ts"), "blah.bundle.js"); + assert_eq!( + get_default_bundle_filename("http://example.com/blah.ts"), + "blah.bundle.js" + ); + assert_eq!(get_default_bundle_filename("blah.js"), "blah.bundle.js"); + assert_eq!( + get_default_bundle_filename("http://example.com/blah.js"), + "blah.bundle.js" + ); +} + pub fn flags_from_vec( args: Vec, ) -> (DenoFlags, DenoSubcommand, Vec) { @@ -510,7 +536,10 @@ pub fn flags_from_vec( ("bundle", Some(bundle_match)) => { flags.allow_write = true; let source_file: &str = bundle_match.value_of("source_file").unwrap(); - let out_file: &str = bundle_match.value_of("out_file").unwrap(); + let out_file = bundle_match + .value_of("out_file") + .map(String::from) + .unwrap_or_else(|| get_default_bundle_filename(source_file)); argv.extend(vec![source_file.to_string(), out_file.to_string()]); DenoSubcommand::Bundle } diff --git a/js/unit_tests.ts b/js/unit_tests.ts index eb6f62bdb..ff9f459e5 100644 --- a/js/unit_tests.ts +++ b/js/unit_tests.ts @@ -50,7 +50,7 @@ import "./performance_test.ts"; import "./permissions_test.ts"; import "./version_test.ts"; -import "../website/app_test.js"; +import "../website/app_test.ts"; import { runIfMain } from "./deps/https/deno.land/std/testing/mod.ts"; diff --git a/tools/build_website.py b/tools/build_website.py new file mode 100755 index 000000000..b519f3853 --- /dev/null +++ b/tools/build_website.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python +# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +import os +from util import run, root_path, build_path + +os.chdir(os.path.join(root_path, "website")) +deno_exe = os.path.join(build_path(), "deno") +run([deno_exe, "bundle", "app.ts", "app.bundle.js"]) diff --git a/tools/upload_website.py b/tools/upload_website.py index 0f9ce9164..e1d100f99 100755 --- a/tools/upload_website.py +++ b/tools/upload_website.py @@ -1,14 +1,18 @@ #!/usr/bin/env python # Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. import os +import sys import tempfile -from util import run, root_path +from util import run, root_path, build_path # Probably run tools/docs.py first. # AWS CLI must be installed separately. os.chdir(os.path.join(root_path, "website")) +deno_exe = os.path.join(build_path(), "deno") +run([sys.executable, "../tools/build_website.py"]) + # Invalidate the cache. run([ "aws", "cloudfront", "create-invalidation", "--distribution-id", diff --git a/website/app.js b/website/app.js deleted file mode 100644 index 9f16e8e45..000000000 --- a/website/app.js +++ /dev/null @@ -1,274 +0,0 @@ -// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. - -// How much to multiply time values in order to process log graphs properly. -const TimeScaleFactor = 10000; - -export async function getJson(path) { - return (await fetch(path)).json(); -} - -function getBenchmarkVarieties(data, benchmarkName) { - // Look at last sha hash. - const last = data[data.length - 1]; - return Object.keys(last[benchmarkName]); -} - -export function createColumns(data, benchmarkName) { - const varieties = getBenchmarkVarieties(data, benchmarkName); - return varieties.map(variety => [ - variety, - ...data.map(d => { - if (d[benchmarkName] != null) { - if (d[benchmarkName][variety] != null) { - const v = d[benchmarkName][variety]; - if (benchmarkName == "benchmark") { - const meanValue = v ? v.mean : 0; - return meanValue || null; - } else { - return v; - } - } - } - return null; - }) - ]); -} - -export function createExecTimeColumns(data) { - return createColumns(data, "benchmark"); -} - -export function createThroughputColumns(data) { - return createColumns(data, "throughput"); -} - -export function createProxyColumns(data) { - return createColumns(data, "req_per_sec_proxy"); -} - -export function createReqPerSecColumns(data) { - return createColumns(data, "req_per_sec"); -} - -export function createMaxLatencyColumns(data) { - return createColumns(data, "max_latency"); -} - -export function createMaxMemoryColumns(data) { - return createColumns(data, "max_memory"); -} - -export function createBinarySizeColumns(data) { - const propName = "binary_size"; - const binarySizeNames = Object.keys(data[data.length - 1][propName]); - return binarySizeNames.map(name => [ - name, - ...data.map(d => { - const binarySizeData = d["binary_size"]; - switch (typeof binarySizeData) { - case "number": // legacy implementation - return name === "deno" ? binarySizeData : 0; - default: - if (!binarySizeData) { - return null; - } - return binarySizeData[name] || null; - } - }) - ]); -} - -export function createThreadCountColumns(data) { - const propName = "thread_count"; - const threadCountNames = Object.keys(data[data.length - 1][propName]); - return threadCountNames.map(name => [ - name, - ...data.map(d => { - const threadCountData = d[propName]; - if (!threadCountData) { - return null; - } - return threadCountData[name] || null; - }) - ]); -} - -export function createSyscallCountColumns(data) { - const propName = "syscall_count"; - const syscallCountNames = Object.keys(data[data.length - 1][propName]); - return syscallCountNames.map(name => [ - name, - ...data.map(d => { - const syscallCountData = d[propName]; - if (!syscallCountData) { - return null; - } - return syscallCountData[name] || null; - }) - ]); -} - -export function createSha1List(data) { - return data.map(d => d.sha1); -} - -export function formatMB(bytes) { - return (bytes / (1024 * 1024)).toFixed(2); -} - -export function formatReqSec(reqPerSec) { - return reqPerSec / 1000; -} - -/** - * @param {string} id The id of dom element - * @param {string[]} categories categories for x-axis values - * @param {any[][]} columns The columns data - * @param {function} onclick action on clicking nodes of chart - * @param {string} yLabel label of y axis - * @param {function} yTickFormat formatter of y axis ticks - */ -function generate( - id, - categories, - columns, - onclick, - yLabel = "", - yTickFormat = null -) { - const yAxis = { - padding: { bottom: 0 }, - min: 0, - label: yLabel - }; - if (yTickFormat) { - yAxis.tick = { - format: yTickFormat - }; - if (yTickFormat == logScale) { - delete yAxis.min; - for (let col of columns) { - for (let i = 1; i < col.length; i++) { - if (col[i] == null || col[i] === 0) { - continue; - } - col[i] = Math.log10(col[i] * TimeScaleFactor); - } - } - } - } - - // @ts-ignore - c3.generate({ - bindto: id, - data: { - columns, - onclick - }, - axis: { - x: { - type: "category", - show: false, - categories - }, - y: yAxis - } - }); -} - -function logScale(t) { - return (Math.pow(10, t) / TimeScaleFactor).toFixed(4); -} - -function formatSecsAsMins(t) { - // TODO use d3.round() - const a = t % 60; - const min = Math.floor(t / 60); - return a < 30 ? min : min + 1; -} - -/** - * @param dataUrl The url of benchramk data json. - */ -export function drawCharts(dataUrl) { - // TODO Using window["location"]["hostname"] instead of - // window.location.hostname because when deno runs app_test.js it gets a type - // error here, not knowing about window.location. Ideally Deno would skip - // type check entirely on JS files. - if (window["location"]["hostname"] != "deno.github.io") { - dataUrl = "https://denoland.github.io/deno/" + dataUrl; - } - return drawChartsFromBenchmarkData(dataUrl); -} - -const proxyFields = [ - "req_per_sec" - //"max_latency" -]; -function extractProxyFields(data) { - for (const row of data) { - for (const field of proxyFields) { - const d = row[field]; - if (!d) continue; - const name = field + "_proxy"; - const newField = {}; - row[name] = newField; - for (const k of Object.getOwnPropertyNames(d)) { - if (k.includes("_proxy")) { - const v = d[k]; - delete d[k]; - newField[k] = v; - } - } - } - } -} -/** - * Draws the charts from the benchmark data stored in gh-pages branch. - */ -export async function drawChartsFromBenchmarkData(dataUrl) { - const data = await getJson(dataUrl); - - // hack to extract proxy fields from req/s fields - extractProxyFields(data); - - const execTimeColumns = createExecTimeColumns(data); - const throughputColumns = createThroughputColumns(data); - const reqPerSecColumns = createReqPerSecColumns(data); - const proxyColumns = createProxyColumns(data); - const maxLatencyColumns = createMaxLatencyColumns(data); - const maxMemoryColumns = createMaxMemoryColumns(data); - const binarySizeColumns = createBinarySizeColumns(data); - const threadCountColumns = createThreadCountColumns(data); - const syscallCountColumns = createSyscallCountColumns(data); - const sha1List = createSha1List(data); - const sha1ShortList = sha1List.map(sha1 => sha1.substring(0, 6)); - - const viewCommitOnClick = _sha1List => d => { - // @ts-ignore - window.open( - `https://github.com/denoland/deno/commit/${_sha1List[d["index"]]}` - ); - }; - - function gen(id, columns, yLabel = "", yTickFormat = null) { - generate( - id, - sha1ShortList, - columns, - viewCommitOnClick(sha1List), - yLabel, - yTickFormat - ); - } - - gen("#exec-time-chart", execTimeColumns, "seconds", logScale); - gen("#throughput-chart", throughputColumns, "seconds", logScale); - gen("#req-per-sec-chart", reqPerSecColumns, "1000 req/sec", formatReqSec); - gen("#proxy-req-per-sec-chart", proxyColumns, "req/sec"); - gen("#max-latency-chart", maxLatencyColumns, "milliseconds", logScale); - gen("#max-memory-chart", maxMemoryColumns, "megabytes", formatMB); - gen("#binary-size-chart", binarySizeColumns, "megabytes", formatMB); - gen("#thread-count-chart", threadCountColumns, "threads"); - gen("#syscall-count-chart", syscallCountColumns, "syscalls"); -} diff --git a/website/app.ts b/website/app.ts new file mode 100644 index 000000000..dfc299d2b --- /dev/null +++ b/website/app.ts @@ -0,0 +1,299 @@ +// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. + +// How much to multiply time values in order to process log graphs properly. +const TimeScaleFactor = 10000; + +export async function getJson(path) { + return (await fetch(path)).json(); +} + +function getBenchmarkVarieties(data, benchmarkName) { + // Look at last sha hash. + const last = data[data.length - 1]; + return Object.keys(last[benchmarkName]); +} + +export function createColumns(data, benchmarkName) { + const varieties = getBenchmarkVarieties(data, benchmarkName); + return varieties.map(variety => [ + variety, + ...data.map(d => { + if (d[benchmarkName] != null) { + if (d[benchmarkName][variety] != null) { + const v = d[benchmarkName][variety]; + if (benchmarkName == "benchmark") { + const meanValue = v ? v.mean : 0; + return meanValue || null; + } else { + return v; + } + } + } + return null; + }) + ]); +} + +export function createExecTimeColumns(data) { + return createColumns(data, "benchmark"); +} + +export function createThroughputColumns(data) { + return createColumns(data, "throughput"); +} + +export function createProxyColumns(data) { + return createColumns(data, "req_per_sec_proxy"); +} + +export function createReqPerSecColumns(data) { + return createColumns(data, "req_per_sec"); +} + +export function createMaxLatencyColumns(data) { + return createColumns(data, "max_latency"); +} + +export function createMaxMemoryColumns(data) { + return createColumns(data, "max_memory"); +} + +export function createBinarySizeColumns(data) { + const propName = "binary_size"; + const binarySizeNames = Object.keys(data[data.length - 1][propName]); + return binarySizeNames.map(name => [ + name, + ...data.map(d => { + const binarySizeData = d["binary_size"]; + switch (typeof binarySizeData) { + case "number": // legacy implementation + return name === "deno" ? binarySizeData : 0; + default: + if (!binarySizeData) { + return null; + } + return binarySizeData[name] || null; + } + }) + ]); +} + +export function createThreadCountColumns(data) { + const propName = "thread_count"; + const threadCountNames = Object.keys(data[data.length - 1][propName]); + return threadCountNames.map(name => [ + name, + ...data.map(d => { + const threadCountData = d[propName]; + if (!threadCountData) { + return null; + } + return threadCountData[name] || null; + }) + ]); +} + +export function createSyscallCountColumns(data) { + const propName = "syscall_count"; + const syscallCountNames = Object.keys(data[data.length - 1][propName]); + return syscallCountNames.map(name => [ + name, + ...data.map(d => { + const syscallCountData = d[propName]; + if (!syscallCountData) { + return null; + } + return syscallCountData[name] || null; + }) + ]); +} + +export function createSha1List(data) { + return data.map(d => d.sha1); +} + +export function formatMB(bytes) { + return (bytes / (1024 * 1024)).toFixed(2); +} + +export function formatReqSec(reqPerSec) { + return reqPerSec / 1000; +} + +/** + * @param {string} id The id of dom element + * @param {string[]} categories categories for x-axis values + * @param {any[][]} columns The columns data + * @param {function} onclick action on clicking nodes of chart + * @param {string} yLabel label of y axis + * @param {function} yTickFormat formatter of y axis ticks + */ +function generate( + id, + categories, + columns, + onclick, + yLabel = "", + yTickFormat = null +) { + const yAxis = { + padding: { bottom: 0 }, + min: 0, + label: yLabel, + tick: null + }; + if (yTickFormat) { + yAxis.tick = { + format: yTickFormat + }; + if (yTickFormat == logScale) { + delete yAxis.min; + for (let col of columns) { + for (let i = 1; i < col.length; i++) { + if (col[i] == null || col[i] === 0) { + continue; + } + col[i] = Math.log10(col[i] * TimeScaleFactor); + } + } + } + } + + // @ts-ignore + c3.generate({ + bindto: id, + data: { + columns, + onclick + }, + axis: { + x: { + type: "category", + show: false, + categories + }, + y: yAxis + } + }); +} + +function logScale(t) { + return (Math.pow(10, t) / TimeScaleFactor).toFixed(4); +} + +function formatSecsAsMins(t) { + // TODO use d3.round() + const a = t % 60; + const min = Math.floor(t / 60); + return a < 30 ? min : min + 1; +} + +/** + * @param dataUrl The url of benchramk data json. + */ +export function drawCharts(dataUrl) { + // TODO Using window["location"]["hostname"] instead of + // window.location.hostname because when deno runs app_test.js it gets a type + // error here, not knowing about window.location. Ideally Deno would skip + // type check entirely on JS files. + if (window["location"]["hostname"] != "deno.github.io") { + dataUrl = "https://denoland.github.io/deno/" + dataUrl; + } + return drawChartsFromBenchmarkData(dataUrl); +} + +const proxyFields = [ + "req_per_sec" + //"max_latency" +]; +function extractProxyFields(data) { + for (const row of data) { + for (const field of proxyFields) { + const d = row[field]; + if (!d) continue; + const name = field + "_proxy"; + const newField = {}; + row[name] = newField; + for (const k of Object.getOwnPropertyNames(d)) { + if (k.includes("_proxy")) { + const v = d[k]; + delete d[k]; + newField[k] = v; + } + } + } + } +} +/** + * Draws the charts from the benchmark data stored in gh-pages branch. + */ +export async function drawChartsFromBenchmarkData(dataUrl) { + const data = await getJson(dataUrl); + + // hack to extract proxy fields from req/s fields + extractProxyFields(data); + + const execTimeColumns = createExecTimeColumns(data); + const throughputColumns = createThroughputColumns(data); + const reqPerSecColumns = createReqPerSecColumns(data); + const proxyColumns = createProxyColumns(data); + const maxLatencyColumns = createMaxLatencyColumns(data); + const maxMemoryColumns = createMaxMemoryColumns(data); + const binarySizeColumns = createBinarySizeColumns(data); + const threadCountColumns = createThreadCountColumns(data); + const syscallCountColumns = createSyscallCountColumns(data); + const sha1List = createSha1List(data); + const sha1ShortList = sha1List.map(sha1 => sha1.substring(0, 6)); + + const viewCommitOnClick = _sha1List => d => { + // @ts-ignore + window.open( + `https://github.com/denoland/deno/commit/${_sha1List[d["index"]]}` + ); + }; + + function gen(id, columns, yLabel = "", yTickFormat = null) { + generate( + id, + sha1ShortList, + columns, + viewCommitOnClick(sha1List), + yLabel, + yTickFormat + ); + } + + gen("#exec-time-chart", execTimeColumns, "seconds", logScale); + gen("#throughput-chart", throughputColumns, "seconds", logScale); + gen("#req-per-sec-chart", reqPerSecColumns, "1000 req/sec", formatReqSec); + gen("#proxy-req-per-sec-chart", proxyColumns, "req/sec"); + gen("#max-latency-chart", maxLatencyColumns, "milliseconds", logScale); + gen("#max-memory-chart", maxMemoryColumns, "megabytes", formatMB); + gen("#binary-size-chart", binarySizeColumns, "megabytes", formatMB); + gen("#thread-count-chart", threadCountColumns, "threads"); + gen("#syscall-count-chart", syscallCountColumns, "syscalls"); +} + +export function main(): void { + window["chartWidth"] = 800; + const overlay = window["document"].getElementById("spinner-overlay"); + + function showSpinner() { + overlay.style.display = "block"; + } + + function hideSpinner() { + overlay.style.display = "none"; + } + + function updateCharts() { + const u = window.location.hash.match("all") ? "./data.json" : "recent.json"; + + showSpinner(); + + drawCharts(u).finally(hideSpinner); + } + updateCharts(); + + window["onhashchange"] = updateCharts; +} diff --git a/website/app_test.js b/website/app_test.js deleted file mode 100644 index b6845a0f7..000000000 --- a/website/app_test.js +++ /dev/null @@ -1,193 +0,0 @@ -// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. - -import { test, testPerm, assert, assertEquals } from "../js/test_util.ts"; -import { - createBinarySizeColumns, - createExecTimeColumns, - createThreadCountColumns, - createSyscallCountColumns, - createSha1List -} from "./app.js"; - -const regularData = [ - { - created_at: "2018-01-01T01:00:00Z", - sha1: "abcdef", - binary_size: { - deno: 100000000, - "main.js": 90000000, - "main.js.map": 80000000, - "snapshot_deno.bin": 70000000 - }, - throughput: { - "100M_tcp": 3.6, - "100M_cat": 3.0, - "10M_tcp": 1.6, - "10M_cat": 1.0 - }, - req_per_sec: { - node: 16000, - deno: 1000 - }, - benchmark: { - hello: { - mean: 0.05 - }, - relative_import: { - mean: 0.06 - }, - cold_hello: { - mean: 0.05 - }, - cold_relative_import: { - mean: 0.06 - } - }, - thread_count: { - set_timeout: 4, - fetch_deps: 6 - }, - syscall_count: { - hello: 600, - fetch_deps: 700 - } - }, - { - created_at: "2018-01-02T01:00:00Z", - sha1: "012345", - binary_size: { - deno: 100000001, - "main.js": 90000001, - "main.js.map": 80000001, - "snapshot_deno.bin": 70000001 - }, - throughput: { - "100M_tcp": 3.6, - "100M_cat": 3.0, - "10M_tcp": 1.6, - "10M_cat": 1.0 - }, - req_per_sec: { - node: 1600, - deno: 3.0 - }, - benchmark: { - hello: { - mean: 0.055 - }, - relative_import: { - mean: 0.065 - }, - cold_hello: { - mean: 0.055 - }, - cold_relative_import: { - mean: 0.065 - } - }, - thread_count: { - set_timeout: 5, - fetch_deps: 7 - }, - syscall_count: { - hello: 700, - fetch_deps: 800 - } - } -]; - -const irregularData = [ - { - created_at: "2018-01-01T01:00:00Z", - sha1: "123", - benchmark: {}, - throughput: {}, - binary_size: {}, - thread_count: {}, - syscall_count: {} - }, - { - created_at: "2018-02-01T01:00:00Z", - sha1: "456", - benchmark: { - hello: {}, - relative_import: {}, - cold_hello: {}, - cold_relative_import: {} - }, - throughput: { - "100M_tcp": 3.0 - }, - binary_size: { - deno: 1 - }, - thread_count: { - set_timeout: 5, - fetch_deps: 7 - }, - syscall_count: { - hello: 700, - fetch_deps: 800 - } - } -]; - -test(function createExecTimeColumnsRegularData() { - const columns = createExecTimeColumns(regularData); - assertEquals(columns, [ - ["hello", 0.05, 0.055], - ["relative_import", 0.06, 0.065], - ["cold_hello", 0.05, 0.055], - ["cold_relative_import", 0.06, 0.065] - ]); -}); - -test(function createExecTimeColumnsIrregularData() { - const columns = createExecTimeColumns(irregularData); - assertEquals(columns, [ - ["hello", null, null], - ["relative_import", null, null], - ["cold_hello", null, null], - ["cold_relative_import", null, null] - ]); -}); - -test(function createBinarySizeColumnsRegularData() { - const columns = createBinarySizeColumns(regularData); - assertEquals(columns, [ - ["deno", 100000000, 100000001], - ["main.js", 90000000, 90000001], - ["main.js.map", 80000000, 80000001], - ["snapshot_deno.bin", 70000000, 70000001] - ]); -}); - -test(function createBinarySizeColumnsIrregularData() { - const columns = createBinarySizeColumns(irregularData); - assertEquals(columns, [["deno", null, 1]]); -}); - -test(function createThreadCountColumnsRegularData() { - const columns = createThreadCountColumns(regularData); - assertEquals(columns, [["set_timeout", 4, 5], ["fetch_deps", 6, 7]]); -}); - -test(function createThreadCountColumnsIrregularData() { - const columns = createThreadCountColumns(irregularData); - assertEquals(columns, [["set_timeout", null, 5], ["fetch_deps", null, 7]]); -}); - -test(function createSyscallCountColumnsRegularData() { - const columns = createSyscallCountColumns(regularData); - assertEquals(columns, [["hello", 600, 700], ["fetch_deps", 700, 800]]); -}); - -test(function createSyscallCountColumnsIrregularData() { - const columns = createSyscallCountColumns(irregularData); - assertEquals(columns, [["hello", null, 700], ["fetch_deps", null, 800]]); -}); - -test(function createSha1ListRegularData() { - const sha1List = createSha1List(regularData); - assertEquals(sha1List, ["abcdef", "012345"]); -}); diff --git a/website/app_test.ts b/website/app_test.ts new file mode 100644 index 000000000..c16487585 --- /dev/null +++ b/website/app_test.ts @@ -0,0 +1,196 @@ +// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. + +import { test, testPerm, assert, assertEquals } from "../js/test_util.ts"; +import { runIfMain } from "../js/deps/https/deno.land/std/testing/mod.ts"; +import { + createBinarySizeColumns, + createExecTimeColumns, + createThreadCountColumns, + createSyscallCountColumns, + createSha1List +} from "./app.ts"; + +const regularData = [ + { + created_at: "2018-01-01T01:00:00Z", + sha1: "abcdef", + binary_size: { + deno: 100000000, + "main.js": 90000000, + "main.js.map": 80000000, + "snapshot_deno.bin": 70000000 + }, + throughput: { + "100M_tcp": 3.6, + "100M_cat": 3.0, + "10M_tcp": 1.6, + "10M_cat": 1.0 + }, + req_per_sec: { + node: 16000, + deno: 1000 + }, + benchmark: { + hello: { + mean: 0.05 + }, + relative_import: { + mean: 0.06 + }, + cold_hello: { + mean: 0.05 + }, + cold_relative_import: { + mean: 0.06 + } + }, + thread_count: { + set_timeout: 4, + fetch_deps: 6 + }, + syscall_count: { + hello: 600, + fetch_deps: 700 + } + }, + { + created_at: "2018-01-02T01:00:00Z", + sha1: "012345", + binary_size: { + deno: 100000001, + "main.js": 90000001, + "main.js.map": 80000001, + "snapshot_deno.bin": 70000001 + }, + throughput: { + "100M_tcp": 3.6, + "100M_cat": 3.0, + "10M_tcp": 1.6, + "10M_cat": 1.0 + }, + req_per_sec: { + node: 1600, + deno: 3.0 + }, + benchmark: { + hello: { + mean: 0.055 + }, + relative_import: { + mean: 0.065 + }, + cold_hello: { + mean: 0.055 + }, + cold_relative_import: { + mean: 0.065 + } + }, + thread_count: { + set_timeout: 5, + fetch_deps: 7 + }, + syscall_count: { + hello: 700, + fetch_deps: 800 + } + } +]; + +const irregularData = [ + { + created_at: "2018-01-01T01:00:00Z", + sha1: "123", + benchmark: {}, + throughput: {}, + binary_size: {}, + thread_count: {}, + syscall_count: {} + }, + { + created_at: "2018-02-01T01:00:00Z", + sha1: "456", + benchmark: { + hello: {}, + relative_import: {}, + cold_hello: {}, + cold_relative_import: {} + }, + throughput: { + "100M_tcp": 3.0 + }, + binary_size: { + deno: 1 + }, + thread_count: { + set_timeout: 5, + fetch_deps: 7 + }, + syscall_count: { + hello: 700, + fetch_deps: 800 + } + } +]; + +test(function createExecTimeColumnsRegularData() { + const columns = createExecTimeColumns(regularData); + assertEquals(columns, [ + ["hello", 0.05, 0.055], + ["relative_import", 0.06, 0.065], + ["cold_hello", 0.05, 0.055], + ["cold_relative_import", 0.06, 0.065] + ]); +}); + +test(function createExecTimeColumnsIrregularData() { + const columns = createExecTimeColumns(irregularData); + assertEquals(columns, [ + ["hello", null, null], + ["relative_import", null, null], + ["cold_hello", null, null], + ["cold_relative_import", null, null] + ]); +}); + +test(function createBinarySizeColumnsRegularData() { + const columns = createBinarySizeColumns(regularData); + assertEquals(columns, [ + ["deno", 100000000, 100000001], + ["main.js", 90000000, 90000001], + ["main.js.map", 80000000, 80000001], + ["snapshot_deno.bin", 70000000, 70000001] + ]); +}); + +test(function createBinarySizeColumnsIrregularData() { + const columns = createBinarySizeColumns(irregularData); + assertEquals(columns, [["deno", null, 1]]); +}); + +test(function createThreadCountColumnsRegularData() { + const columns = createThreadCountColumns(regularData); + assertEquals(columns, [["set_timeout", 4, 5], ["fetch_deps", 6, 7]]); +}); + +test(function createThreadCountColumnsIrregularData() { + const columns = createThreadCountColumns(irregularData); + assertEquals(columns, [["set_timeout", null, 5], ["fetch_deps", null, 7]]); +}); + +test(function createSyscallCountColumnsRegularData() { + const columns = createSyscallCountColumns(regularData); + assertEquals(columns, [["hello", 600, 700], ["fetch_deps", 700, 800]]); +}); + +test(function createSyscallCountColumnsIrregularData() { + const columns = createSyscallCountColumns(irregularData); + assertEquals(columns, [["hello", null, 700], ["fetch_deps", null, 800]]); +}); + +test(function createSha1ListRegularData() { + const sha1List = createSha1List(regularData); + assertEquals(sha1List, ["abcdef", "012345"]); +}); + +runIfMain(import.meta); diff --git a/website/benchmarks.html b/website/benchmarks.html index fa1b140e9..fd68faee2 100644 --- a/website/benchmarks.html +++ b/website/benchmarks.html @@ -230,31 +230,11 @@ - + + diff --git a/website/manual.md b/website/manual.md index 8b3d37521..1810cdc7a 100644 --- a/website/manual.md +++ b/website/manual.md @@ -591,30 +591,9 @@ if (import.meta.main) { ### Flags -```shellsession -deno -A secure runtime for JavaScript and TypeScript built with V8, Rust, and Tokio. - -Docs: https://deno.land/manual.html -Modules: https://github.com/denoland/deno_std -Bugs: https://github.com/denoland/deno/issues - -To run the REPL: - - deno - -To execute a sandboxed script: - - deno https://deno.land/welcome.ts - -To evaluate code from the command line: - - deno eval "console.log(30933 + 404)" - -To get help on the another subcommands (run in this case): - - deno help run +Use `deno help` to see the help text. +``` USAGE: deno [FLAGS] [OPTIONS] [SUBCOMMAND] @@ -640,6 +619,7 @@ OPTIONS: SUBCOMMANDS: + + +``` + +Here we assume there's an exported function `main()` from `website.ts`. + +```js +// website.ts +export main() { + console.log("hello from the web browser"); +} +``` + ## Import maps Deno supports [import maps](https://github.com/WICG/import-maps). -- cgit v1.2.3