1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00
denoland-deno/cli/tests/unit
Marcos Casagrande 7599990a4f
perf(ext/streams): optimize streams (#20649)
This PR introduces several optimizations to streams

### Highlights:
- `ReadableStream` constructor: +20% iter/s.
- `WritableStream` constructor: +50% iter/s.
- `TransformStream` constructor: +30% iter/s.
- `ReadableStream` iterator (both 2 and 20 chunks): +42% and +25%
iter/s.
- `ReadableByteStream` iterator (both 2 and 20 chunks): +39% and +20%
iter/s.

### Benchmarks
**main**
```
cpu: 13th Gen Intel(R) Core(TM) i9-13900H
runtime: deno 1.37.0 (x86_64-unknown-linux-gnu)

benchmark                                      time (avg)        iter/s             (min … max)       p75       p99      p995
----------------------------------------------------------------------------------------------- -----------------------------
ReadableStream constructor                    294.52 ns/iter   3,395,392.9 (277.92 ns … 618.26 ns) 292.66 ns 353.87 ns 618.26 ns
WritableStream constructor                    235.51 ns/iter   4,246,065.3 (213.04 ns … 306.35 ns) 236.77 ns 279.08 ns 281.32 ns
TransformStream constructor                   672.52 ns/iter   1,486,938.7 (652.15 ns … 880.74 ns) 670.11 ns 880.74 ns 880.74 ns
ReadableStream - iterator (2 chunks)           10.44 µs/iter      95,757.9   (8.97 µs … 830.91 µs)  10.22 µs  14.74 µs  18.93 µs
ReadableStream - iterator (20 chunks)          21.93 µs/iter      45,593.4   (18.8 µs … 864.97 µs)  20.57 µs  57.15 µs 137.16 µs
ReadableStream - reader (2 chunks)              7.09 µs/iter     140,987.2     (7.03 µs … 7.18 µs)   7.13 µs   7.18 µs   7.18 µs
ReadableStream - reader (20 chunks)            18.41 µs/iter      54,324.2    (15.7 µs … 252.7 µs)  17.14 µs  68.88 µs  94.08 µs
ReadableByteStream - iterator (2 chunks)       11.06 µs/iter      90,375.1   (9.75 µs … 404.69 µs)  10.88 µs   16.6 µs  29.69 µs
ReadableByteStream - iterator (20 chunks)      26.71 µs/iter      37,435.0  (22.98 µs … 508.34 µs)  25.25 µs  85.28 µs 155.65 µs
ReadableByteStream - reader (2 chunks)          7.99 µs/iter     125,131.1     (7.92 µs … 8.13 µs)   8.01 µs   8.13 µs   8.13 µs
ReadableByteStream - reader (20 chunks)        23.46 µs/iter      42,618.5  (20.28 µs … 414.66 µs)  21.94 µs  90.52 µs 147.38 µs
```

**this PR**
```
cpu: 13th Gen Intel(R) Core(TM) i9-13900H
runtime: deno 1.37.0 (x86_64-unknown-linux-gnu)

benchmark                                      time (avg)        iter/s             (min … max)       p75       p99      p995
----------------------------------------------------------------------------------------------- -----------------------------
ReadableStream constructor                    235.48 ns/iter   4,246,584.3 (223.12 ns … 504.65 ns)  234.3 ns 290.84 ns 311.12 ns
WritableStream constructor                    156.31 ns/iter   6,397,537.3 (148.54 ns … 211.13 ns) 157.49 ns 199.82 ns 208.23 ns
TransformStream constructor                   471.29 ns/iter   2,121,815.3 (452.53 ns … 791.41 ns) 468.62 ns 540.36 ns 791.41 ns
ReadableStream - iterator (2 chunks)            7.32 µs/iter     136,705.4   (6.35 µs … 639.97 µs)    7.1 µs  12.12 µs  20.98 µs
ReadableStream - iterator (20 chunks)          17.48 µs/iter      57,195.1  (14.48 µs … 289.06 µs)  16.06 µs  76.98 µs 114.61 µs
ReadableStream - reader (2 chunks)              6.86 µs/iter     145,847.9      (6.8 µs … 6.97 µs)   6.88 µs   6.97 µs   6.97 µs
ReadableStream - reader (20 chunks)            16.88 µs/iter      59,227.7  (14.04 µs … 311.29 µs)  15.39 µs  74.95 µs  97.45 µs
ReadableByteStream - iterator (2 chunks)        7.94 µs/iter     125,881.2   (6.86 µs … 811.16 µs)   7.69 µs  11.43 µs   16.6 µs
ReadableByteStream - iterator (20 chunks)      22.23 µs/iter      44,978.2  (18.98 µs … 590.11 µs)  20.73 µs  45.13 µs  159.8 µs
ReadableByteStream - reader (2 chunks)           7.4 µs/iter     135,206.9     (7.36 µs … 7.42 µs)    7.4 µs   7.42 µs   7.42 µs
ReadableByteStream - reader (20 chunks)        21.03 µs/iter      47,555.6  (17.75 µs … 357.66 µs)  19.52 µs  98.69 µs  146.5 µs
```

---------

Co-authored-by: Luca Casonato <hello@lcas.dev>
2023-10-13 14:30:09 +02:00
..
abort_controller_test.ts chore: add copyright_checker tool and add the missing copyright (#17285) 2023-01-13 16:51:32 +09:00
blob_test.ts chore: update std submodule and its imports (#17408) 2023-01-15 21:09:26 +01:00
body_test.ts fix(ext/formdata): support multiple headers in FormData (#20801) 2023-10-05 19:28:44 +02:00
broadcast_channel_test.ts fix: check if BroadcastChannel is open before sending (#17366) 2023-01-12 13:43:36 +01:00
buffer_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
build_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
cache_api_test.ts fix(dts): make globals available on globalThis (#19438) 2023-07-03 14:36:55 -04:00
chmod_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
chown_test.ts chore: fix typos (#19572) 2023-06-26 09:10:27 -04:00
command_test.ts fix: Deno.Command - improve error message when cwd is not a directory (#20460) 2023-09-18 17:48:54 +00:00
console_test.ts fix(cli): ensure that an exception in getOwnPropertyDescriptor('constructor') doesn't break Deno.inspect (#20568) 2023-09-19 18:24:19 +00:00
copy_file_test.ts fix(runtime/fs): preserve permissions in copyFileSync for macOS (#17412) 2023-01-14 13:45:30 +00:00
custom_event_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
dir_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
dom_exception_test.ts chore: add copyright_checker tool and add the missing copyright (#17285) 2023-01-13 16:51:32 +09:00
error_stack_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
error_test.ts fix: add WouldBlock error (#17339) 2023-02-12 23:14:33 +01:00
esnext_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
event_target_test.ts fix(ext/web): Copy EventTarget list before dispatch (#19360) 2023-06-04 18:03:44 -06:00
event_test.ts perf(ext/event): optimize Event constructor (#20181) 2023-08-17 10:35:18 +02:00
fetch_test.ts fix(cli/test): clear connection pool after tests (#20680) 2023-09-26 19:46:06 +09:00
ffi_test.ts fix(ext/ffi): use anybuffer for op_ffi_ptr_of (#20820) 2023-10-08 14:02:07 +09:00
file_test.ts feat(ext/web): Add name to Deno.customInspect of File objects (#20415) 2023-09-14 07:06:58 +02:00
filereader_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
files_test.ts feat: TypeScript 5.0.2 (except decorators) (#18294) 2023-03-21 15:46:40 +00:00
flock_test.ts chore(core): fix flaky flock_test on windows (#19477) 2023-06-12 20:30:29 +00:00
fs_events_test.ts chore: fix typos (#19572) 2023-06-26 09:10:27 -04:00
get_random_values_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
globals_test.ts fix: define window.name (#20804) 2023-10-08 22:12:59 +00:00
headers_test.ts fix(core): introduce SafeRegExp to primordials (#17592) 2023-03-01 08:14:16 +09:00
http_test.ts fix(cli/test): clear connection pool after tests (#20680) 2023-09-26 19:46:06 +09:00
internals_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
intl_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
io_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
jupyter_test.ts feat(unstable): add Deno.jupyter.display API (#20819) 2023-10-12 22:32:38 +00:00
kv_queue_test_no_db_close.ts fix(ext/kv): don't panic if listening on queues and KV is not closed (#20317) 2023-08-29 11:24:44 -07:00
kv_queue_undelivered_test.ts feat(kv) queue implementation (#19459) 2023-06-13 17:49:57 -07:00
kv_test.ts fix(ext/kv): send queue wake messages accross different kv instances (#20465) 2023-09-29 11:40:36 -07:00
link_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
make_temp_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
message_channel_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
metrics_test.ts refactor: rewrite several extension ops to op2 (#20457) 2023-10-05 14:34:38 +02:00
mkdir_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
navigator_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
net_test.ts feat(unstable): add unix domain socket support to Deno.serve (#20759) 2023-10-04 11:37:39 +09:00
network_interfaces_test.ts chore: add copyright_checker tool and add the missing copyright (#17285) 2023-01-13 16:51:32 +09:00
opcall_test.ts chore: Use relative paths for assert imports to avoid test flakes (#19427) 2023-06-08 18:10:37 +00:00
os_test.ts feat(runtime/os): add Deno.env.has() (#17315) 2023-01-09 20:19:55 +01:00
path_from_url_test.ts chore: add copyright_checker tool and add the missing copyright (#17285) 2023-01-13 16:51:32 +09:00
performance_test.ts chore(cli): measure performance against wall-clock (#18357) 2023-03-22 18:06:29 +00:00
permissions_test.ts feat: Add sync APIs for "Deno.permissions" (#17019) 2023-01-25 00:42:44 +01:00
process_test.ts feat(lint): add Deno.run to no-deprecated-deno-api (#18869) 2023-04-27 02:52:52 +00:00
progressevent_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
promise_hooks_test.ts refactor: remove Deno.core (#16881) 2023-01-24 18:54:10 +01:00
read_dir_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
read_file_test.ts fix(runtime): Extract error code for all OS error variants (#17958) 2023-03-19 00:01:50 +00:00
read_link_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
read_text_file_test.ts Revert "refactor: don't expose Deno[Deno.internal].core namespace" (#18881) 2023-04-28 00:37:03 +02:00
README.md chore: fix flaky netListenUnrefAndRef (#16892) 2022-12-02 12:41:52 -05:00
real_path_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
ref_unref_test.ts refactor: remove Deno.core (#16881) 2023-01-24 18:54:10 +01:00
remove_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
rename_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
request_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
resources_test.ts chore(cli): One Rust test per JS and Node unit test file (#19199) 2023-05-22 13:35:59 -06:00
response_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
serve_test.ts fix(ext/http): Deno.Server should not be thenable (#20723) 2023-10-09 12:43:14 +09:00
signal_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
stat_test.ts refactor(core): Extract deno_core (#19658) 2023-07-02 00:00:14 +00:00
stdio_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
streams_test.ts perf(ext/streams): optimize streams (#20649) 2023-10-13 14:30:09 +02:00
structured_clone_test.ts chore: add copyright_checker tool and add the missing copyright (#17285) 2023-01-13 16:51:32 +09:00
symlink_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
sync_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
test_util.ts feat(unstable): add unix domain socket support to Deno.serve (#20759) 2023-10-04 11:37:39 +09:00
testing_test.ts fix(test): allow explicit undefined for boolean test options (#18786) 2023-04-21 15:32:37 +02:00
text_encoding_test.ts chore: fix typos (#19572) 2023-06-26 09:10:27 -04:00
timers_test.ts Revert "refactor: rewrite ops that use 'deferred' to use 'op2(async(lazy))' (#20303) (#20370) 2023-09-04 17:05:06 -04:00
tls_test.ts fix(ext/net): implement a graceful error on an invalid SSL certificate (#20157) 2023-08-15 00:11:12 +00:00
truncate_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
tty_color_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
tty_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
umask_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
url_search_params_test.ts chore: fix typos (#19572) 2023-06-26 09:10:27 -04:00
url_test.ts fix(ext/url): throw TypeError for empty argument (#18896) 2023-04-30 12:24:34 +02:00
urlpattern_test.ts fix(dts): URLPatternComponentResult groups should have possibly undefined key values (#18643) 2023-04-26 19:15:25 -04:00
utime_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
version_test.ts feat: TypeScript 5.2 (#20425) 2023-09-09 15:03:21 -04:00
wasm_test.ts chore: add copyright_checker tool and add the missing copyright (#17285) 2023-01-13 16:51:32 +09:00
webcrypto_test.ts fix(ext/crypto): correctly limit ECDSA and hash algorithms (#18030) 2023-03-05 12:34:07 +00:00
websocket_test.ts feat(ext/node): http2.connect() API (#19671) 2023-09-15 21:51:25 +02:00
webstorage_test.ts fix(ext/webstorage): check size of inputs before insert (#18087) 2023-03-09 12:28:51 +00:00
worker_permissions_test.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
worker_types.ts chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
write_file_test.ts fix(ops): Always close cancel handles for read_async/write_async (#17736) 2023-02-11 14:19:13 +02:00
write_text_file_test.ts chore: add copyright_checker tool and add the missing copyright (#17285) 2023-01-13 16:51:32 +09:00

Deno runtime tests

Files in this directory are unit tests for Deno runtime.

Testing Deno runtime code requires checking API under different runtime permissions. To accomplish this all tests exercised are created using Deno.test() function.

import {} from "./test_util.ts";

Deno.test(function simpleTestFn(): void {
  // test code here
});

Deno.test(
  {
    ignore: Deno.build.os === "windows",
    permissions: { read: true, write: true },
  },
  function complexTestFn(): void {
    // test code here
  },
);

Running tests

There are two ways to run unit_test_runner.ts:

# Run all tests.
cargo run --bin deno -- test --allow-all --unstable --location=http://js-unit-tests/foo/bar cli/tests/unit/

# Run a specific test module
cargo run --bin deno -- test --allow-all --unstable --location=http://js-unit-tests/foo/bar cli/tests/unit/files_test.ts

Http server

target/debug/test_server is required to run when one's running unit tests. During CI it's spawned automatically, but if you want to run tests manually make sure that server is spawned otherwise there'll be cascade of test failures.