import typia from 'typia'
interface User {
id?: number
name?: string
avatar?: string
mobile?: string
}
const user: User = {
id: 1,
name: 'Bob',
avatar: 'https://avatar.com/bob',
mobile: '12345678901'
}
let stringify = typia.json.createStringify<User>()
performance.mark('test')
for (let i = 0; i < 1e7; i++) {
stringify(user)
}
let result = performance.measure('test')
console.log(result.duration) // = 3066.775059
The $tail function execution time is positively correlated with length of string because of str[str.length -1].
The longer of the string, the longer time it takes.
The
$tail
function execution time is positively correlated with length of string because ofstr[str.length -1]
. The longer of the string, the longer time it takes.As the generator knows the last prop expression is
undefined === input.mobile
, just pass second argumentundefined !== input.mobile
to$tail
.After do this, result.duration reduce to
1733.192805
on my machine.