-
-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Faker.Person.FirstName seems really slow compared to Faker.Name.FirstName #248
Comments
Hi @dvdbot, To replace void Main()
{
var userFaker = new Faker<User>()
.RuleFor(u => u.FirstName, f => f.Name.FirstName())
.RuleFor(u => u.LastName, f => f.Name.LastName())
.RuleFor(u => u.Email, (f, u) => f.Internet.Email(u.FirstName, u.LastName));
userFaker.Generate(5).Dump();
}
public class User
{
public string FirstName {get;set;}
public string LastName {get;set;}
public string Email{get;set;}
}
If you're strictly concerned about performance, other performance ideas you might want to consider are described below:
This is the best I can do with the information you've provided. If you want this investigated further, you'll have to post some kind of code that can reproduce the issue, so we can further investigate. With issues like this, I prefer to have concrete code that reproduces an issue that you're seeing otherwise, it's easy to chase phantoms. Also, if we do find that something in the email code is too slow like traversing the trie for transliteration, current code like that won't change unless we can come up with an equivalent solution that offers better code maintainability without increasing complexity. Feel free to re-open the issue if you can provide more information or pinpoint any performance issues in the source. Let me know if that helps. Thanks, |
It's not only the email - The thing that stumped me the most is that the |
Yes, you're right. Accessing Before each The code for that should be here: Lines 97 to 102 in 398d55d
Each new person will have a startup cost of Lines 85 to 121 in 398d55d
Which is probably why you're seeing such a high, first-time, initialization cost accessing |
Hey @dvdbot , yesterday, I did a quick perf test and found similar results as you've described. Without using any I wrote a lazy-loaded property I'm still thinking about the consequences of changing Pros
Cons
Todo
Also, a change like this would have to be put into a major version bump. Then, all this weighed against adding a performance section in the README under Advanced Topics, Guidance, and Best Practices. |
When using |
When using Other than When using Here's a good example: void Main()
{
var easyFaker = new Faker<User>()
.RuleFor(u => u.FirstName, f => f.Person.FirstName)
.RuleFor(u => u.LastName, f => f.Person.LastName)
.RuleFor(u => u.FullName, f => f.Person.FullName)
.RuleFor(u => u.Email, f => f.Person.Email)
.RuleFor(u => u.Gender, f => f.Person.Gender);
easyFaker.Generate().Dump();
var complexFaker = new Faker<User>()
.RuleFor(u => u.Gender, f => f.PickRandom<Bogus.DataSets.Name.Gender>())
.RuleFor(u => u.FirstName, (f, u) => f.Name.FirstName(u.Gender) )
.RuleFor(u => u.LastName, (f, u) => f.Name.LastName(u.Gender))
.RuleFor(u => u.FullName, (f, u) => $"{u.FirstName} {u.LastName}")
.RuleFor(u => u.Email, (f, u) => f.Internet.Email(u.FirstName, u.LastName));
complexFaker.Generate().Dump();
}
public class User{
public string FirstName { get;set; }
public string LastName { get; set; }
public string FullName { get; set; }
public string Email { get; set;}
public Bogus.DataSets.Name.Gender Gender {get;set;}
} Notice, with I'm kinda leaning toward keeping the code unchanged and adding a new section in the readme that provides some performance guidelines. But I did want to give my thoughts on the subject as to why this is a little bit of a complicated situation. |
Version Information
What locale are you using with Bogus?
default so I guess english locale
What's the problem?
I'm generating 1.000.000 users but when I'm using anything related to the Faker.Person it really slows down -> 1.000.000 in 43secs to 2+ min -> if I use Faker.Name.FirstName instead of Faker.Person.FirstName it is just quick as expected -> got to say, I'm using multithreading using Parallel.For and came across this issue: #234
What possible solutions have you considered?
Using Faker.Name.FirstName instead of Faker.Person.Name but how would I replace Faker.Person.Email?
Do you have sample code to show what you're trying to do?
I can share the repo if needed (have to push it online first)
(Please be complete. Include any class models necessary to run your code.)
The text was updated successfully, but these errors were encountered: