Skip to content

Commit fa8edcd

Browse files
committed
chore: wip
1 parent 1d7a1cc commit fa8edcd

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,11 @@ nanofaker is designed for performance and efficiency:
339339

340340
**Performance:**
341341
-**9 out of 9 benchmarks won** (100% win rate!)
342-
-**11.68x faster than @faker-js/faker** on average
343-
- 🚀 **32.36M ops/s** for city generation
344-
- 🔑 **19.90M ops/s** for UUID generation (40.8x faster!)
345-
- 📊 **5.50ms** to generate 10,000 complex user objects
342+
-**9.28x faster than @faker-js/faker** on average
343+
- 🚀 **34.04M ops/s** for country generation
344+
- 🔑 **20.50M ops/s** for UUID generation (41.2x faster!)
345+
- 📧 **10.44M ops/s** for email generation (15.5x faster!)
346+
- 📊 **6.90ms** to generate 10,000 complex user objects
346347

347348
**Package Size:**
348349
- 📦 **174 KB** published (core package only)
@@ -354,11 +355,11 @@ nanofaker is designed for performance and efficiency:
354355

355356
| Operation | nanofaker | @faker-js/faker | Speedup |
356357
|-----------|-----------|-----------------|---------|
357-
| Full Name Generation | 24.27M ops/s | 653.72K ops/s | **37.1x faster** |
358-
| UUID Generation | 19.90M ops/s | 487.60K ops/s | **40.8x faster** |
359-
| City Generation | 32.36M ops/s | 927.67K ops/s | **34.9x faster** |
360-
| Email Generation | 6.59M ops/s | 642.75K ops/s | **10.3x faster** |
361-
| Complex Objects (10k) | 5.50ms | 96.36ms | **17.5x faster** |
358+
| UUID Generation | 20.50M ops/s | 497.69K ops/s | **41.2x faster** |
359+
| Full Name Generation | 24.76M ops/s | 678.37K ops/s | **36.5x faster** |
360+
| Country Generation | 34.04M ops/s | 1.05M ops/s | **32.4x faster** |
361+
| Email Generation | 10.44M ops/s | 674.02K ops/s | **15.5x faster** |
362+
| Complex Objects (10k) | 6.90ms | 64.04ms | **9.3x faster** |
362363

363364
### Running Benchmarks
364365

packages/benchmarks/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Comprehensive benchmarks comparing nanofaker against other popular JavaScript/Ty
1515
### Key Advantages
1616

1717
**nanofaker offers:**
18-
-**Fastest performance** - 11.68x faster than @faker-js/faker on average
18+
-**Fastest performance** - 9.28x faster than @faker-js/faker on average
1919
-**Smallest size** - 24.7x smaller than @faker-js/faker (4.1 MB savings)
2020
-**Fewest files** - 6.1x fewer files than @faker-js/faker
2121
-**Complete locale coverage** - 100% for all 26 languages

packages/core/src/modules/internet.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,27 @@ import type { Random } from '../random'
22
import type { LocaleDefinition, PasswordOptions } from '../types'
33

44
export class InternetModule {
5+
private static readonly SEPARATORS = ['.', '_', '-', '']
6+
private domainWordsCache: string[] | null = null
7+
58
constructor(
69
private random: Random,
710
private locale: LocaleDefinition,
811
) {}
912

13+
/**
14+
* Get cached lowercase domain words
15+
*/
16+
private getDomainWords(): string[] {
17+
if (!this.domainWordsCache) {
18+
const companyNames = this.locale.company.name ?? ['company', 'tech', 'digital']
19+
this.domainWordsCache = companyNames.map(name =>
20+
name.toLowerCase().replace(/[^a-z0-9]/g, ''),
21+
).filter(name => name.length > 0)
22+
}
23+
return this.domainWordsCache
24+
}
25+
1026
/**
1127
* Generate a random email address
1228
* @example faker.internet.email() // 'john.doe@example.com'
@@ -15,7 +31,7 @@ export class InternetModule {
1531
// Optimized: avoid array spreading by selecting from combined length
1632
let firstName: string
1733
if (options?.firstName) {
18-
firstName = options.firstName
34+
firstName = options.firstName.toLowerCase()
1935
}
2036
else {
2137
const maleLen = this.locale.person.firstNameMale.length
@@ -37,11 +53,10 @@ export class InternetModule {
3753

3854
const lastName = options?.lastName ?? this.random.arrayElement(this.locale.person.lastName).toLowerCase()
3955
const provider = options?.provider ?? this.random.arrayElement(this.locale.internet.domainSuffix ?? ['com', 'net', 'org'])
56+
const separator = this.random.arrayElement(InternetModule.SEPARATORS)
57+
const domain = this.random.arrayElement(this.getDomainWords())
4058

41-
const separators = ['.', '_', '-', '']
42-
const separator = this.random.arrayElement(separators)
43-
44-
return `${firstName}${separator}${lastName}@${this.domainWord()}.${provider}`
59+
return `${firstName}${separator}${lastName}@${domain}.${provider}`
4560
}
4661

4762
/**
@@ -182,9 +197,7 @@ export class InternetModule {
182197
* @example faker.internet.domainWord() // 'example'
183198
*/
184199
domainWord(): string {
185-
return this.random.arrayElement(this.locale.company.name ?? ['Company', 'Tech', 'Digital'])
186-
.toLowerCase()
187-
.replace(/[^a-z0-9]/g, '')
200+
return this.random.arrayElement(this.getDomainWords())
188201
}
189202

190203
/**

0 commit comments

Comments
 (0)