Use [] to find tag! Example: [flutter, javascript]

Hono VS Express

Hono VS Express

access_time 22 October 2024 remove_red_eye 1443 Kali spellcheck 1768 Kata, 10543 Karakter
#hono #comparison #express

In this comparison, I will compare hono vs express.js. Some of the things I will compare are documentation, community, performance, and feature completeness.

Documentation

Like most major frameworks. Hono and Express have complete documentation. Which can even be used by beginners. Having easy navigation, which we can even know where we should start learning this from. However, in terms of the beauty of the interface, I personally prefer the Hono documentation website, because Hono has a menu on the left (sidebar), which is easier to reach.

Community

If we look now, express has a much larger number of downloads than hono.

Current number of express downloads:

NPM Downloads

Current number of hono downloads:

npm

From the numbers above, we can see that express has a higher number of communities than hono. However, historically, since 2023, hono has had a greater increase in the number of downloads, while express remains at the same number.

History of express download count on NPM:


History of hono download count on NPM:


From the number of histories, it is possible that the number of hono users will increase even more in the future.

Performance

In performance testing, I tried to compare hono fairly with express. Starting from ping trials with several virtual users, and experiments using several features that might be comparable. The comparison of these three frameworks only compares hono typescript with runtime type bun, hono javascript with runtime type node.js, and express javascript with runtime type node.js.

Testing 1000 Virtual Users with K6

This time, we try to compare the results of testing using k6 with 1000 virtual users in 1 second. The test was carried out in 30 seconds. and here are the results.

K6 Testing Only with Ping Pong Code

In this test, I tried to create a code with a /ping route that returns pong! and logs "someone pinged me". Here is the code from the 2 frameworks.

Ping Hono Code Typescript Bun & Ping Hono Code Javascript Node.js

import { Hono } from 'hono'

const app = new Hono()

app.get( '/ping', ( c ) =>
{
  console.log( "someone pinged me" )
  return c.text( 'pong!' )
} )

export default {
  port: 3001,
  fetch: app.fetch,
}
Node.js Express Javascript Ping Code

const express = require('express');
const app = express();
const port = 3001;

app.get('/ping', (req, res) => {
  console.log("someone pinged me");
  res.send('pong!');
});

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`);
});


Ping Hono Typescript Bun Test Results

     data_received..................: 3.6 MB 119 kB/s
     data_sent......................: 2.5 MB 83 kB/s
     http_req_blocked...............: avg=225.58µs min=1µs  med=3µs    max=31.66ms p(90)=7µs    p(95)=16.04µs
     http_req_connecting............: avg=206.36µs min=0s   med=0s     max=17.92ms p(90)=0s     p(95)=0s     
     http_req_duration..............: avg=4.24ms   min=48µs med=3.18ms max=39.06ms p(90)=9.37ms p(95)=10.78ms
       { expected_response:true }...: avg=4.24ms   min=48µs med=3.18ms max=39.06ms p(90)=9.37ms p(95)=10.78ms
     http_req_failed................: 0.00%  0 out of 30000
     http_req_receiving.............: avg=126.23µs min=4µs  med=17µs   max=16.26ms p(90)=55µs   p(95)=102µs  
     http_req_sending...............: avg=336.67µs min=2µs  med=9µs    max=28.52ms p(90)=642µs  p(95)=1.45ms 
     http_req_tls_handshaking.......: avg=0s       min=0s   med=0s     max=0s      p(90)=0s     p(95)=0s     
     http_req_waiting...............: avg=3.77ms   min=34µs med=2.96ms max=29.01ms p(90)=8.55ms p(95)=9.6ms  
     http_reqs......................: 30000  992.329853/s
     iteration_duration.............: avg=1s       min=1s   med=1s     max=1.04s   p(90)=1.01s  p(95)=1.01s  
     iterations.....................: 30000  992.329853/s
     vus............................: 1000   min=1000       max=1000
     vus_max........................: 1000   min=1000       max=1000

Ping Hono Javascript Node.js Test Results

     data_received..................: 4.9 MB 164 kB/s
     data_sent......................: 2.5 MB 83 kB/s
     http_req_blocked...............: avg=4.9ms   min=0s   med=2µs    max=1.01s   p(90)=6µs    p(95)=31µs  
     http_req_connecting............: avg=4.88ms  min=0s   med=0s     max=1s      p(90)=0s     p(95)=0s    
     http_req_duration..............: avg=2.22ms  min=0s   med=1.05ms max=57.11ms p(90)=3.31ms p(95)=4.12ms
       { expected_response:true }...: avg=2.21ms  min=44µs med=1.03ms max=57.11ms p(90)=3.24ms p(95)=4.08ms
     http_req_failed................: 1.53%  459 out of 29866
     http_req_receiving.............: avg=27.26µs min=0s   med=13µs   max=7.84ms  p(90)=45µs   p(95)=68µs  
     http_req_sending...............: avg=54.76µs min=0s   med=5µs    max=4.3ms   p(90)=55µs   p(95)=172µs 
     http_req_tls_handshaking.......: avg=0s      min=0s   med=0s     max=0s      p(90)=0s     p(95)=0s    
     http_req_waiting...............: avg=2.14ms  min=0s   med=985µs  max=56.35ms p(90)=3.23ms p(95)=4.05ms
     http_reqs......................: 29866  991.048311/s
     iteration_duration.............: avg=1s      min=1s   med=1s     max=2.02s   p(90)=1s     p(95)=1s    
     iterations.....................: 29866  991.048311/s
     vus............................: 1000   min=1000         max=1000
     vus_max........................: 1000   min=1000         max=1000

Node.js Javascript Ping Express Test Results

     data_received..................: 6.6 MB 217 kB/s
     data_sent......................: 2.5 MB 83 kB/s
     http_req_blocked...............: avg=2.16ms  min=0s   med=2µs   max=202.62ms p(90)=8µs    p(95)=8.53ms 
     http_req_connecting............: avg=2.15ms  min=0s   med=0s    max=202.49ms p(90)=0s     p(95)=8.41ms 
     http_req_duration..............: avg=2.37ms  min=0s   med=707µs max=61.1ms   p(90)=4.95ms p(95)=8.48ms 
       { expected_response:true }...: avg=2.08ms  min=77µs med=630µs max=61.1ms   p(90)=3.61ms p(95)=5.99ms 
     http_req_failed................: 5.13%  1539 out of 30000
     http_req_receiving.............: avg=12.69µs min=0s   med=9µs   max=862µs    p(90)=25µs   p(95)=32µs   
     http_req_sending...............: avg=35.86µs min=0s   med=3µs   max=4.04ms   p(90)=15µs   p(95)=51.04µs
     http_req_tls_handshaking.......: avg=0s      min=0s   med=0s    max=0s       p(90)=0s     p(95)=0s     
     http_req_waiting...............: avg=2.32ms  min=0s   med=688µs max=61.08ms  p(90)=4.9ms  p(95)=8.24ms 
     http_reqs......................: 30000  989.805596/s
     iteration_duration.............: avg=1s      min=1s   med=1s    max=1.2s     p(90)=1s     p(95)=1.03s  
     iterations.....................: 30000  989.805596/s
     vus............................: 1000   min=1000          max=1000
     vus_max........................: 1000   min=1000          max=1000


Ping Test Results Conclusion

Overall, hono typescript bun is superior to express. Especially in stability and efficiency in receiving HTTP requests.

Here are the reasons why hono is superior to express.

  1. Hono typescript bun has no failed requests at all, unlike the express results which have a failure rate of around 5.13%.
  2. Hono typescript bun has faster blocking and request connection times, where Hono has an average blocked time of 225.58µs and an average request connection time of 206.36µs, in contrast to Hono which is only in micro seconds, Express has an average blocked time of 2.16ms and an average request connection time of 2.15ms.
  3. Hono has a more stable request waiting compared to express, although express has a lower average request waiting (2.32ms) and hono reaches (3.77ms), but hono has a lower maximum value, namely 29.01ms while express reaches 61.08ms.

Although express has a slightly faster average request time, hono's stability and reliability are better than express. So the overall result is hono bun typescript is better than express node javascript in this test. Need further testing? we can discuss here.

Next let's compare, hono javascript node.js vs express javascript node.js.

Overall hono javascript node.js is superior to express javascript node.js. Here are the reasons why hono is superior:

  1. Hono javascript node.js is superior in speed, having a faster average request time of 2.22ms with a maximum value of 57.11ms while express javascript node.js has an average request time of 2.37ms with a maximum value of 61.1ms.
  2. Hono javascript node.js has a lower request failed rate, which is 1.53%, while express has a request failed rate of 5.13%.
  3. Hono javascript node.js is slightly faster in completing requests, which is 991 per second while express is 990 per second.

From these results, it can be concluded that hono typescript bun or hono javascript node.js is better than express javascript node.js.

Completeness of Features

In this session we will discuss middleware and utilities. Because both hono and express. Have features that I think are more than enough for making production applications.

Middleware

Hono has a lot of middleware, from basic auth to including 3rd Party middleware, but express also has a lot of middleware. So for this comparison, it might depend on our respective projects, what kind of middleware we need. So I think they both provide middleware services that are very helpful for our projects. But if we dive a little into what middleware is in their documentation, maybe for a start up project, hono middleware will be very helpful for us.

Utility

On the utility side, the features provided in the hono and express documentation have relatively the same number. However, hono has more advantages. Like helpers for css, html helpers that we can use by rendering jsx, which even from the three things I have not found any helpers in the express utility documentation. But basically, because express has a large community, we can use 3rd party for this.

Conclusion

Don't hesitate to try using hono, even though this framework is relatively new, but the stability, completeness of features, and comfort in coding are extraordinary. And we can use the typescript language which makes it easier for us to identify data types. As for which one is better, you decide for your project.

Don't forget to keep smile 😊, and always be happy 😃

Navigasi Konten