Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CodSpeed

on:
push:
branches:
- main
- next/*
- feat/*
- fix/*
- perf/*
- v1
- v1.*
pull_request:
branches:
- main
- next/*
- feat/*
- fix/*
- perf/*
- v1
- v1.*
workflow_dispatch:

permissions:
contents: read
id-token: write

jobs:
benchmarks:
name: Run Benchmarks
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".node-version"
cache: "npm"

- name: Install NPM Dependencies
run: npm ci

- name: Run Benchmarks with CodSpeed
uses: CodSpeedHQ/action@v4
with:
mode: simulation
run: npx vitest bench --run --config vitest.bench.config.js
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![UnitTests](https://badgen.net/https/wzcozo2uwacu4dfvawkdkmxi640guflx.lambda-url.us-east-1.on.aws?cache=300)](https://github.com/Semantic-Org/Semantic-Next/actions/workflows/ci.yml)
[![E2ETests](https://badgen.net/https/ien5pqfy4lsyqy5a2vegyvevpa0petpj.lambda-url.us-east-1.on.aws?cache=300)](https://github.com/Semantic-Org/Semantic-Next/actions/workflows/ci.yml)
[![Coverage](https://badgen.net/https/fnipttzwzg6ieemy4winuladuu0jhqef.lambda-url.us-east-1.on.aws?cache=300)](https://github.com/Semantic-Org/Semantic-Next/actions/workflows/ci.yml)
[![CodSpeed](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/Semantic-Org/Semantic-Next?utm_source=badge)

A modern, lightweight UI framework built with Web Components.

Expand Down
92 changes: 92 additions & 0 deletions benchmarks/arrays.bench.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { bench, describe } from 'vitest';
import {
difference,
flatten,
groupBy,
intersection,
range,
sortBy,
unique,
uniqueItems,
} from '../packages/utils/src/arrays.js';

describe('array utilities', () => {
const smallArray = range(0, 20);
const mediumArray = range(0, 100);
const largeArray = range(0, 500);

bench('unique - small array', () => {
unique([...smallArray, ...smallArray]);
});

bench('unique - medium array', () => {
unique([...mediumArray, ...mediumArray]);
});

bench('flatten - nested arrays', () => {
const nested = [[1, 2], [3, 4], [[5, 6], [7, 8]], [9, 10]];
flatten(nested);
});

bench('flatten - deeply nested', () => {
const nested = [[[[[1, 2]]], [[3, 4]]], [[[5, 6]], [[7, 8]]]];
flatten(nested);
});

bench('sortBy - numeric property', () => {
const data = mediumArray.map((i) => ({ id: i, value: Math.random() }));
sortBy(data, 'value');
});

bench('sortBy - multiple keys', () => {
const data = mediumArray.map((i) => ({
category: i % 5,
priority: i % 3,
value: Math.random(),
}));
sortBy(data, ['category', 'priority', 'value']);
});

bench('groupBy - small dataset', () => {
const data = smallArray.map((i) => ({ category: i % 5, value: i }));
groupBy(data, 'category');
});

bench('groupBy - large dataset', () => {
const data = largeArray.map((i) => ({ category: i % 10, value: i }));
groupBy(data, 'category');
});

bench('intersection - small arrays', () => {
const arr1 = range(0, 20);
const arr2 = range(10, 30);
const arr3 = range(15, 35);
intersection(arr1, arr2, arr3);
});

bench('intersection - largearrays', () => {
const arr1 = range(0, 200);
const arr2 = range(100, 300);
const arr3 = range(150, 350);
intersection(arr1, arr2, arr3);
});

bench('difference - small arrays', () => {
const arr1 = range(0, 20);
const arr2 = range(10, 30);
difference(arr1, arr2);
});

bench('difference - large arrays', () => {
const arr1 = range(0, 200);
const arr2 = range(100, 300);
difference(arr1, arr2);
});

bench('uniqueItems - multiple arrays', () => {
const arr1 = range(0, 30);
const arr2 = range(20, 50);
const arr3 = range(40, 70);
uniqueItems(arr1, arr2, arr3);
});
});
86 changes: 86 additions & 0 deletions benchmarks/strings.bench.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { bench, describe } from 'vitest';
import {
camelToKebab,
capitalize,
capitalizeWords,
escapeHTML,
getArticle,
joinWords,
kebabToCamel,
toTitleCase,
truncate,
} from '../packages/utils/src/strings.js';

describe('string utilities', () => {
const shortString = 'hello world';
const longString = 'the quick brown fox jumps over the lazy dog '.repeat(10);
const htmlString = '<script>alert("XSS")</script> & <div>content</div>';
const kebabString = 'this-is-a-kebab-case-string-with-many-words';
const camelString = 'thisIsACamelCaseStringWithManyWords';

bench('kebabToCamel - short string', () => {
kebabToCamel('hello-world');
});

bench('kebabToCamel - long string', () => {
kebabToCamel(kebabString);
});

bench('camelToKebab - short string', () => {
camelToKebab('helloWorld');
});

bench('camelToKebab - long string', () => {
camelToKebab(camelString);
});

bench('capitalize', () => {
capitalize(shortString);
});

bench('capitalizeWords', () => {
capitalizeWords(longString);
});

bench('toTitleCase - short', () => {
toTitleCase('the quick brown fox');
});

bench('toTitleCase - long', () => {
toTitleCase(longString);
});

bench('joinWords - small list', () => {
joinWords(['apple', 'banana', 'cherry']);
});

bench('joinWords - large list with options', () => {
const words = Array.from({ length: 20 }, (_, i) => `item${i}`);
joinWords(words, { oxford: true, quotes: true });
});

bench('getArticle', () => {
getArticle('umbrella');
getArticle('house');
});

bench('truncate - short text', () => {
truncate(shortString, 50);
});

bench('truncate - long text with word boundary', () => {
truncate(longString, 100, { wordBoundary: true });
});

bench('truncate - long text without word boundary', () => {
truncate(longString, 100, { wordBoundary: false });
});

bench('escapeHTML - simple', () => {
escapeHTML('<div>test</div>');
});

bench('escapeHTML - complex', () => {
escapeHTML(htmlString);
});
});
Loading