Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Commit

Permalink
Added nested object for benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
ktutnik committed Jun 23, 2019
1 parent fff3954 commit c908a8e
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions test/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,55 @@ import reflect from 'tinspector';
import joi from "joi"
import { createConverter as create } from "../src/converter"

@reflect.parameterProperties()
class Address {
constructor(public zip:string, public city:string, number:number){}
}

@reflect.parameterProperties()
class MyData {
constructor(
public name: string,
public date: Date
public date: Date,
public address: Address
) { }
}
const schema = joi.object({
name: joi.string(),
date: joi.date()
date: joi.date(),
address: joi.object({
zip:joi.string(),
city:joi.string(),
number: joi.number()
})
});

const convert = createConverter()
const newConvert = create(MyData);

const value = { name: "Lorem ipsum", date: "2018-1-1", address: {zip: "123", city: "CA", number: "123"} };

(async () => {
console.log(await convert({ name: "Lorem ipsum", date: "2018-1-1" }, MyData))
console.log( newConvert({ name: "Lorem ipsum", date: "2018-1-1" }))
console.log(schema.validate({ name: "Lorem ipsum", date: "2018-1-1" }))
console.log(await convert(value, MyData))
console.log( newConvert(value))
console.log(schema.validate(value))

const iteration = 4000000;
console.time("TypedConverter")
for (let i = 0; i < iteration; i++) {
const result = await convert({ name: "Lorem ipsum", date: "2018-1-1" }, MyData)
const result = await convert(value, MyData)
}
console.timeEnd("TypedConverter")

console.time("NewLogic")
for (let i = 0; i < iteration; i++) {
const result = newConvert({ name: "Lorem ipsum", date: "2018-1-1" })
const result = newConvert(value)
}
console.timeEnd("NewLogic")

console.time("Joi")
for (let i = 0; i < iteration; i++) {
const result = schema.validate({ name: "Lorem ipsum", date: "2018-1-1" })
const result = schema.validate(value)
}
console.timeEnd("Joi")
})()

0 comments on commit c908a8e

Please sign in to comment.