aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-04-07 22:07:24 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-04-07 22:07:24 -0700
commit63995da2c2f7f1e2b4bd135387c311200d7cbad0 (patch)
tree09decca7c8c53f85c7e24894bdf948badf31d8d0
parentf3b118d0ad97e7b13c8151da02e3ce6e657705c4 (diff)
downloadbun-63995da2c2f7f1e2b4bd135387c311200d7cbad0.tar.gz
bun-63995da2c2f7f1e2b4bd135387c311200d7cbad0.tar.zst
bun-63995da2c2f7f1e2b4bd135387c311200d7cbad0.zip
example
-rw-r--r--README.md49
-rw-r--r--examples/http.ts2
2 files changed, 33 insertions, 18 deletions
diff --git a/README.md b/README.md
index 9aa3248fb..afed074d9 100644
--- a/README.md
+++ b/README.md
@@ -74,7 +74,38 @@ If using Linux, kernel version 5.6 or higher is strongly recommended, but the mi
## Using bun.js - a new JavaScript runtime environment
-bun.js is an all-in-one JavaScript runtime environment focused on performance and developer experience.
+bun.js is an all-in-one JavaScript runtime environment focused on performance, developer experience, and compatibility with the JavaScript ecosystem.
+
+```ts
+// http.ts
+export default {
+ port: 3000,
+ fetch(request: Request) {
+ return new Response("Hello World");
+ },
+};
+
+// bun ./http.ts
+```
+
+<details>
+
+<summary>view benchmark</summary>
+
+| Requests per second | OS | CPU | bun version |
+| ---------------------------------------------------------------------- | ----- | ------------------------------ | ----------- |
+| [260,000](https://twitter.com/jarredsumner/status/1512040623200616449) | macOS | Apple Silicon M1 Max | 0.0.76 |
+| [160,000](https://twitter.com/jarredsumner/status/1511988933587976192) | Linux | AMD Ryzen 5 3600 6-Core 2.2ghz | 0.0.76 |
+
+Measured with [http_load_test](https://github.com/uNetworking/uSockets/blob/master/examples/http_load_test.c) by running:
+
+```bash
+./http_load_test 20 127.0.0.1 3000
+```
+
+</details>
+
+bun.js prefers Web API compatibility or node API compatibility instead of designing new APIs when possible.
- TypeScript & JSX support is builtin, powered by Bun's JavaScript transpiler
- ESM & CommonJS modules are supported (internally, bun.js uses ESM)
@@ -87,24 +118,8 @@ bun.js is an all-in-one JavaScript runtime environment focused on performance an
- `.env` files automatically load into `process.env` and `Bun.env`
- top level await
-bun.js prefers Web API compatibility or node API compatibility instead of designing new APIs when possible.
-
The runtime uses JavaScriptCore, the JavaScript engine powering WebKit and Safari. Some web APIs like [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) and [`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL) directly use [Safari's implementation](https://github.com/Jarred-Sumner/bun/blob/e0011fd6baf2fe2b12d1b2a909981da1a183cdad/src/javascript/jsc/bindings/webcore/JSFetchHeaders.cpp#L1).
-[fast HTTP server](https://twitter.com/jarredsumner/status/1505559457832443906) in 6 lines of code:
-
-```ts
-// http.ts
-export default {
- port: 3000,
- fetch(request: Request) {
- return new Response("Hello World");
- },
-};
-
-// bun ./http.ts
-```
-
`cat` clone that runs [2x faster than GNU cat](https://twitter.com/jarredsumner/status/1511707890708586496) for large files on Linux
```js
diff --git a/examples/http.ts b/examples/http.ts
index 3a44f421e..97caf6bfc 100644
--- a/examples/http.ts
+++ b/examples/http.ts
@@ -1,6 +1,6 @@
// Start a fast HTTP server from a function
Bun.serve({
- async fetch(req: Request) {
+ fetch(req: Request) {
return new Response(`Echo: ${req.url}`);
},