why faker is very slow

hi there

i’m using faker to generate some fake name and email, but it is very very slow, why?

thanks in advanced

this is my piece of code for fake,

to create 5 users, its take 5 seconds

I don’t know why ! :expressionless:

        $userInfo = [];

        $userInfoForDb = [];

        $faker = Factory::create('fa_IR');


            $countPostedData = \Yii::$app->request->post()['count'];

            for($index = 1; $index <= $countPostedData; $index++){

                $userInfo[$index]['email'] = $faker->email;

                $userInfo[$index]['password'] = $faker->password;

                $userInfoForDb[$index] = '("' . $userInfo[$index]['email'] .'","'. \Yii::$app->security->generatePasswordHash($userInfo[$index]['password']) . '")';



            if(\Yii::$app->request->post()['count'] !== 0){

                \Yii::$app->db->createCommand('INSERT INTO user(email, password_hash) VALUES' . implode(',', $userInfoForDb))->execute();



I don’t think it’s Faker. The password hashing is a more likely cause of the problem: yii\base\Security::generatePasswordHash() is intentionally slow. Its speed can be adjusted by setting the $cost parameter but don’t make it too fast for production.