Issue type:
[?] documentation issue
Database system/driver:
[*] postgres
TypeORM version:
[*] latest
Node version: v9.7.1
TypeORM version: 0.1.20
Code to reproduce the context of the question :
import "reflect-metadata";
import {createConnection} from "typeorm";
import { User } from "./entity/User";
createConnection().then(async connection => {
const users: User[] = [];
for (let i = 1; i <= 1000; i++) {
const user = new User();
user.firstName = `Jean`;
user.lastName = `Perf`;
user.age = 1;
users.push(user);
}
console.time("queryCreation");
const query = connection.createQueryBuilder()
.insert()
.into(User)
.values(users);
console.timeEnd("queryCreation");
console.time("queryExecInsert");
query.execute();
console.timeEnd("queryExecInsert");
console.time("queryExecSave");
connection.manager.save(users)
console.timeEnd("queryExecSave");
}).catch(error => console.log(error));
queryCreation: 1.153ms
queryExecInsert: 2152.322ms
queryExecSave: 0.357ms
queryCreation: 1.371ms
queryExecInsert: 2325.678ms
queryExecSave: 0.450ms
queryCreation: 0.999ms
queryExecInsert: 1989.534ms
queryExecSave: 0.315ms
#
It gets similar result as https://github.com/typeorm/typeorm/blob/master/test/benchmark/bulk-save/bulk-save.ts.
From the doc (http://typeorm.io/#/insert-query-builder) it says that QueryBuilder insert "is the most efficient way in terms of performance to insert rows into your database".
But given result above .save seems to be a lot quicker, so I don't understand. Any guess ?
Try it on @next. Save mechanizm was completely refactored and now save is ultra fast and insert is super-ultra fast and a bit faster then save. npm i typeorm@next.
Most helpful comment
Try it on
@next. Save mechanizm was completely refactored and nowsaveis ultra fast andinsertis super-ultra fast and a bit faster thensave.npm i typeorm@next.