Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] Maybe add the comparison and benchmark with other css frameworks ? #1

Open
jasondg opened this issue Jul 16, 2023 · 3 comments

Comments

@jasondg
Copy link

jasondg commented Jul 16, 2023

No description provided.

@IanDxSSXX
Copy link
Owner

Did't find a resonable benchmark but make a little comparison with emotion.js:

source code:

import { css } from '@iandx/easy-css'
import { css as emotionCss } from "@emotion/css"

function simplePerformanceTest(tag: string, easyFunc: (i: number) => any, emotionFunc: (i: number) => any) {
  console.log(`[----${tag}----]`)
  for (const round of [10, 100, 1000, 10000]) {
    console.log(`----${round}----`)
    console.time(`easy-css`)
    for (let i = 0; i < round; i++) {
      easyFunc(i)
    }
    console.timeEnd(`easy-css`)
    console.time(`emotion`)
    for (let i = 0; i < round; i++) {
      emotionFunc(i)
    }
    console.timeEnd(`emotion`)
  }
  console.log("")
}

// pre-rendered for easy-css
simplePerformanceTest(
  "reuse",
  () => {
    css`
      color: red;
      font-weight: bold;
      display: flex;
    `
  },
  () => {
    emotionCss`
      color: red;
      font-weight: bold;
      display: flex;
    `
  }
)

simplePerformanceTest(
  "new",
  i => {
    css`
      color: red;
      font-weight: bold;
      display: flex;
      font-size: ${i}px;
    `
  },
  i => {
    emotionCss`
      color: red;
      font-weight: bold;
      display: flex;
      font-size: ${i}px;
    `
  }
)

Result:
image

So in the "reuse" part, because that the css string is static, so with easy-css's pre-parsing tech, it costs almost nothing whatever the number of the round is. And in the "new" part, for that everytime the index "i" is new, there's no way to statically analyze it in build time, however as you can see the "dynamic" runtime cost is way lower than emotion. (notice that emotion stucks when the round is 10,000)

@jasondg
Copy link
Author

jasondg commented Jul 17, 2023

@IanDxSSXX
Copy link
Owner

Demo here
Only implement runtime easy-css, because static pre-parsed one is the same with pure css therotically.
Here's the result
First render:
image
Render multiple times:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants