Created
August 24, 2017 16:53
-
-
Save FabianWesner/d4e3b34bd44db62b80aa8f40d49544b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function test1Action() | |
| { | |
| SpyCustomerQuery::create()->deleteAll(); | |
| $ms = microtime(true); | |
| $con = Propel::getConnection(); | |
| $con->beginTransaction(); | |
| for ($i = 0; $i < 10000; $i++) { | |
| $string = time() . $i; | |
| $customer = new SpyCustomer(); | |
| $customer->setFkLocale(1); | |
| $customer->setCustomerReference($string); | |
| $customer->setEmail($string); | |
| $customer->setSalutation('Mr'); | |
| $customer->setFirstName($string); | |
| $customer->setLastName($string); | |
| $customer->setCompany($string); | |
| $customer->setGender('Male'); | |
| $customer->save(); | |
| } | |
| $con->commit(); | |
| die('<pre><b>' . print_r(SpyCustomerQuery::create()->count() . ' - ' . number_format(microtime(true) - $ms, 4), true) . '</b>' . PHP_EOL . __CLASS__ . ' ' . __LINE__); | |
| } | |
| public function test2Action() | |
| { | |
| // | |
| SpyCustomerQuery::create()->deleteAll(); | |
| $ms = microtime(true); | |
| $con = Propel::getConnection(); | |
| $con->beginTransaction(); | |
| $sqls = 'INSERT INTO "spy_customer" ("id_customer", "fk_locale", "customer_reference", "email", "salutation", "first_name", "last_name", "company", "gender") VALUES'; | |
| for ($i = 0; $i < 10000; $i++) { | |
| $string = time() . $i; | |
| $dataFetcher = $con->query("SELECT nextval('spy_customer_pk_seq')"); | |
| $idCustomer = $dataFetcher->fetchColumn(); | |
| $sql = <<<EOD | |
| ({$idCustomer}, 1, '{$string}', '{$string}@mail0.com', 0, '{$string}Firstname', '{$string}Lastname', '{$string}Company', 0), | |
| EOD; | |
| $sqls .= $sql; | |
| } | |
| $sqls = rtrim($sqls, ','); | |
| $con->exec($sqls); | |
| $con->commit(); | |
| die('<pre><b>' . print_r(SpyCustomerQuery::create()->count() . ' - ' . number_format(microtime(true) - $ms, 4), true) . '</b>' . PHP_EOL . __CLASS__ . ' ' . __LINE__); | |
| } | |
| public function test3Action() | |
| { | |
| SpyCustomerQuery::create()->deleteAll(); | |
| $ms = microtime(true); | |
| $con = Propel::getConnection(); | |
| $con->beginTransaction(); | |
| $sqls = ''; | |
| for ($i = 0; $i < 1000; $i++) { | |
| $string = time() . $i; | |
| $sql = <<<EOD | |
| INSERT INTO "spy_customer" ("id_customer", "fk_locale", "customer_reference", "email", "salutation", "first_name", "last_name", "company", "gender") VALUES | |
| ((nextval('spy_customer_pk_seq')), 1, '{$string}', '{$string}@mail0.com', 0, '{$string}Firstname', '{$string}Lastname', '{$string}Company', 0); | |
| EOD; | |
| $sqls .= $sql; | |
| } | |
| $sqls = rtrim($sqls, ','); | |
| $con->exec($sqls); | |
| $con->commit(); | |
| die('<pre><b>' . print_r(SpyCustomerQuery::create()->count() . ' - ' . number_format(microtime(true) - $ms, 4), true) . '</b>' . PHP_EOL . __CLASS__ . ' ' . __LINE__); | |
| } | |
| public function test4Action() | |
| { | |
| SpyCustomerQuery::create()->deleteAll(); | |
| $ms = microtime(true); | |
| $con = Propel::getConnection(); | |
| for ($j = 0; $j < 10; $j++) { | |
| $con->beginTransaction(); | |
| $rows = []; | |
| $prepSql = 'INSERT INTO "spy_customer" ("fk_locale", "customer_reference", "email", "salutation", "first_name", "last_name", "company", "gender", "id_customer") VALUES'; | |
| for ($i = 0; $i < 1000; $i++) { | |
| $string = time() . $i.$j; | |
| $prepSql .= ' (?, ?, ?, ?, ?, ?, ?, ?, (nextval(\'spy_customer_pk_seq\'))),'; | |
| $rows[] = '1'; | |
| $rows[] = $string; | |
| $rows[] = $string; | |
| $rows[] = '0'; | |
| $rows[] = $string; | |
| $rows[] = $string; | |
| $rows[] = $string; | |
| $rows[] = '0'; | |
| } | |
| $prepSql = rtrim($prepSql, ','); | |
| $stmt = $con->prepare($prepSql); | |
| $stmt->execute($rows); | |
| $con->commit(); | |
| } | |
| die('<pre><b>' . print_r(SpyCustomerQuery::create()->count() . ' - ' . number_format(microtime(true) - $ms, 4), true) . '</b>' . PHP_EOL . __CLASS__ . ' ' . __LINE__); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment