Skip to content

Commit

Permalink
chore: remove bench-related dependencies
Browse files Browse the repository at this point in the history
Also disable skr-canvas in the bench
  • Loading branch information
yisibl committed Feb 7, 2023
1 parent b3b30d0 commit aa93f74
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 639 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<a href="https://github.com/yisibl/resvg-js/actions"><img alt="GitHub CI Status" src="https://github.com/yisibl/resvg-js/workflows/CI/badge.svg?branch=main"></a>
<a href="https://www.npmjs.com/package/@resvg/resvg-js"><img src="https://img.shields.io/npm/v/@resvg/resvg-js.svg?sanitize=true" alt="@resvg/resvg-js npm version"></a>
<a href="https://npmcharts.com/compare/@resvg/resvg-js?minimal=true"><img src="https://img.shields.io/npm/dm/@resvg/resvg-js.svg?sanitize=true" alt="@resvg/resvg-js downloads"></a>
[![Rust 1.65+](https://img.shields.io/badge/rust-1.65+-orange.svg)](https://www.rust-lang.org)

> resvg-js is a high-performance SVG renderer and toolkit, powered by Rust based [resvg](https://github.com/RazrFalcon/resvg/), with Node.js backend using [napi-rs](https://github.com/napi-rs/napi-rs), also a pure WebAssmebly backend.
Expand Down Expand Up @@ -166,6 +167,11 @@ See [playground](wasm/index.html), it is also possible to [call Wasm in Node.js]
## Sample Benchmark
```shell
npm i benny@3.x sharp@0.x @types/sharp svg2img@0.x
npm run bench
```
```shell
Running "resize width" suite...
resvg-js(Rust):
Expand Down
92 changes: 46 additions & 46 deletions benchmark/bench.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { promises as fs } from 'fs'
import { join } from 'path'

import { createCanvas, Image } from '@napi-rs/canvas'
// import { createCanvas, Image } from '@napi-rs/canvas'
import b from 'benny'
import sharp from 'sharp'
import svg2img from 'svg2img'
Expand Down Expand Up @@ -37,25 +37,25 @@ async function run() {
}),

// test from https://github.com/Brooooooklyn/canvas/blob/main/example/resize-svg.js
b.add('skr-canvas(Rust)', () => {
const image = new Image()
image.src = svg1
// b.add('skr-canvas(Rust)', () => {
// const image = new Image()
// image.src = svg1

const w = 1200
const h = 623
// const w = 1200
// const h = 623

// resize SVG
image.width = w
image.height = h
// // resize SVG
// image.width = w
// image.height = h

// create a canvas of the same size as the image
const canvas = createCanvas(w, h)
const ctx = canvas.getContext('2d')
// // create a canvas of the same size as the image
// const canvas = createCanvas(w, h)
// const ctx = canvas.getContext('2d')

// fill the canvas with the image
ctx.drawImage(image, 0, 0)
canvas.toBuffer('image/png')
}),
// // fill the canvas with the image
// ctx.drawImage(image, 0, 0)
// canvas.toBuffer('image/png')
// }),

b.add('svg2img(canvg + node-canvas)', () => {
svg2img(svg1.toString('utf8'), { width: 1200, height: 623 }, function (_error, _buffer) {})
Expand Down Expand Up @@ -93,25 +93,25 @@ async function run() {
}),

// test from https://github.com/Brooooooklyn/canvas/blob/main/example/resize-svg.js
b.add('skr-canvas(Rust)', () => {
const image = new Image()
image.src = icon
// b.add('skr-canvas(Rust)', () => {
// const image = new Image()
// image.src = icon

const w = 386
const h = 386
// const w = 386
// const h = 386

// resize SVG
image.width = w
image.height = h
// // resize SVG
// image.width = w
// image.height = h

// create a canvas of the same size as the image
const canvas = createCanvas(w, h)
const ctx = canvas.getContext('2d')
// // create a canvas of the same size as the image
// const canvas = createCanvas(w, h)
// const ctx = canvas.getContext('2d')

// fill the canvas with the image
ctx.drawImage(image, 0, 0)
canvas.toBuffer('image/png')
}),
// // fill the canvas with the image
// ctx.drawImage(image, 0, 0)
// canvas.toBuffer('image/png')
// }),

b.add('svg2img(canvg + node-canvas)', () => {
svg2img(icon.toString('utf8'), { width: 386, height: 386 }, function (_error, _buffer) {})
Expand Down Expand Up @@ -139,25 +139,25 @@ async function run() {
await sharp(tiger).toBuffer()
}),

b.add('skr-canvas(Rust)', () => {
const image = new Image()
image.src = tiger
// b.add('skr-canvas(Rust)', () => {
// const image = new Image()
// image.src = tiger

const w = 900
const h = 900
// const w = 900
// const h = 900

// resize SVG
image.width = w
image.height = h
// // resize SVG
// image.width = w
// image.height = h

// create a canvas of the same size as the image
const canvas = createCanvas(w, h)
const ctx = canvas.getContext('2d')
// // create a canvas of the same size as the image
// const canvas = createCanvas(w, h)
// const ctx = canvas.getContext('2d')

// fill the canvas with the image
ctx.drawImage(image, 0, 0)
canvas.toBuffer('image/png')
}),
// // fill the canvas with the image
// ctx.drawImage(image, 0, 0)
// canvas.toBuffer('image/png')
// }),

b.add('svg2img(canvg + node-canvas)', () => {
svg2img(tiger.toString('utf8'), { width: 900, height: 900 }, function (_error, _buffer) {})
Expand Down
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,12 @@
"version": "napi version"
},
"devDependencies": {
"@napi-rs/canvas": "^0.1.25",
"@napi-rs/cli": "^2.14.5",
"@napi-rs/cli": "^2.14.6",
"@swc-node/register": "^1.5.1",
"@types/node": "^18.0.0",
"@types/sharp": "^0.31.0",
"@typescript-eslint/eslint-plugin": "^5.30.3",
"@typescript-eslint/parser": "^5.30.3",
"ava": "^5.0.0",
"benny": "^3.7.1",
"copyfiles": "^2.4.1",
"dts-bundle-generator": "^6.12.0",
"esbuild": "^0.17.0",
Expand All @@ -96,7 +93,6 @@
"node-fetch": "2.x",
"npm-run-all": "^4.1.5",
"prettier": "^2.7.1",
"sharp": "^0.31.0",
"typescript": "^4.7.4"
},
"lint-staged": {
Expand Down
Loading

1 comment on commit aa93f74

@vercel
Copy link

@vercel vercel bot commented on aa93f74 Feb 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

resvg-js – ./

resvg-js.vercel.app
resvg-js-git-main-yisibl.vercel.app
resvg-js-yisibl.vercel.app

Please sign in to comment.