1. DatabaseSeeder
./database/seeds/DatabaseSeeder.php
1 2 3 4 | public function run() { $this ->call(Orders1TableSeeder:: class ); } |
2. make seeder
$ php artisan make:seeder Orders1TableSeeder
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | use Illuminate\Support\Facades\DB; public function run() { DB::table( 'orders1' )->insert([ 'user_id' =>rand(1,10), 'supplier_num' =>rand(1,10), 'supplier_id1' =>rand(1,10), 'supplier_id2' =>rand(1,10), 'supplier_id3' =>rand(1,10), 'supplier_subtotal1' =>rand(100,10000), 'supplier_subtotal2' =>rand(100,10000), 'supplier_subtotal3' =>rand(100,10000), 'total' =>rand(100,10000), 'product_num' =>rand(1,10), 'product_id1' =>rand(1,10), 'product_id2' =>rand(1,10), 'product_id3' =>rand(1,10), 'product_id4' =>rand(1,10), 'product_id5' =>rand(1,10), 'qty1' =>rand(1,10), 'qty2' =>rand(1,10), 'qty3' =>rand(1,10), 'qty4' =>rand(1,10), 'qty5' =>rand(1,10), 'subtotal1' =>rand(100,10000), 'subtotal2' =>rand(100,10000), 'subtotal3' =>rand(100,10000), 'subtotal4' =>rand(100,10000), 'subtotal5' =>rand(100,10000), 'detail' => '' , ]); } |
3. db:seed
$ php artisan db:seed
mysql> select * from orders1;
+—-+———+————–+————–+————–+————–+——————–+——————–+——————–+———+————-+————-+————-+————-+————-+————-+——+——+——+——+——+———–+———–+———–+———–+———–+——–+————+————+
| id | user_id | supplier_num | supplier_id1 | supplier_id2 | supplier_id3 | supplier_subtotal1 | supplier_subtotal2 | supplier_subtotal3 | total | product_num | product_id1 | product_id2 | product_id3 | product_id4 | product_id5 | qty1 | qty2 | qty3 | qty4 | qty5 | subtotal1 | subtotal2 | subtotal3 | subtotal4 | subtotal5 | detail | created_at | updated_at |
+—-+———+————–+————–+————–+————–+——————–+——————–+——————–+———+————-+————-+————-+————-+————-+————-+——+——+——+——+——+———–+———–+———–+———–+———–+——–+————+————+
| 1 | 6 | 6 | 6 | 9 | 9 | 6713.00 | 7337.00 | 6092.00 | 9497.00 | 6 | 10 | 2 | 10 | 2 | 2 | 10 | 5 | 5 | 6 | 6 | 4003.00 | 7581.00 | 1475.00 | 2006.00 | 4347.00 | | NULL | NULL |
+—-+———+————–+————–+————–+————–+——————–+——————–+——————–+———+————-+————-+————-+————-+————-+————-+——+——+——+——+——+———–+———–+———–+———–+———–+——–+————+————+
1 row in set (0.00 sec)
mysql> truncate table orders1;
4. seederで2000件データを挿入する
for文で2000件入れる
1 2 3 4 5 6 7 8 9 | public function run() { for ( $i =0; $i <=2000; $i ++){ DB::table( 'orders1' )->insert([ // 省略 ]); } } |
$ php artisan db:seed
5. mysql文
mysql.sql
1 | select * from orders1 where supplier_num = 1; |
$ time (cat mysql.sql | mysql -u root -p test > /dev/null)
Enter password:
real 0m3.099s // プログラムの呼び出しから終了までにかかった実時間
user 0m0.009s // プログラム自体の処理時間(秒)(ユーザCPU時間)
sys 0m0.012s // プログラムを処理するために、OSが処理をした時間
OK
これはカラム数29だが、カラム数を50, 100と増やした場合に、実行時間がどれ位変化するかテストする。
うむ、そこそこテストっぽいことやってる。