Skip to content

Use getRandomBytes and specific hashcode to speed up text generation#530

Merged
snuyanzin merged 1 commit intodatafaker-net:mainfrom
snuyanzin:text
Nov 5, 2022
Merged

Use getRandomBytes and specific hashcode to speed up text generation#530
snuyanzin merged 1 commit intodatafaker-net:mainfrom
snuyanzin:text

Conversation

@snuyanzin
Copy link
Collaborator

By usage of assumption that in case of number of different symbols less than or equals 256 it's possible to use generated byte array and symbols should be unique it could be drastically speed up
before


Benchmark                        Mode  Cnt     Score     Error   Units
DatafakerSimpleMethods.text10   thrpt   10  1451.104 ± 125.972  ops/ms
DatafakerSimpleMethods.text100  thrpt   10   164.296 ±  20.433  ops/ms

after

Benchmark                        Mode  Cnt     Score     Error   Units
DatafakerSimpleMethods.text10   thrpt   10  4360.216 ± 529.892  ops/ms
DatafakerSimpleMethods.text100  thrpt   10   895.668 ±  98.985  ops/ms

benchmark

...
 private static final net.datafaker.Faker DATA_FAKER = new net.datafaker.Faker();
    Text.TextRuleConfig config10 = Text.TextSymbolsBuilder.builder()
            .with(Text.EN_LOWERCASE)
            .withMinLength(10)
            .withMaxLength(10)
            .build(DATA_FAKER);
    Text.TextRuleConfig config100 = Text.TextSymbolsBuilder.builder()
            .with(Text.EN_LOWERCASE)
            .withMinLength(100)
            .withMaxLength(100)
            .build(DATA_FAKER);
    public static void main(String[] args) throws RunnerExceptio
...
    @Benchmark
    @BenchmarkMode(Mode.Throughput)
    public void text10(Blackhole blackhole) {
        blackhole.consume(DATA_FAKER.text().text(config10));
    }

    @Benchmark
    @BenchmarkMode(Mode.Throughput)
    public void text100(Blackhole blackhole) {
        blackhole.consume(DATA_FAKER.text().text(config100));
    }
...

@codecov-commenter
Copy link

codecov-commenter commented Nov 5, 2022

Codecov Report

Merging #530 (a06d43a) into main (08eb70c) will decrease coverage by 0.56%.
The diff coverage is 39.65%.

@@             Coverage Diff              @@
##               main     #530      +/-   ##
============================================
- Coverage     92.49%   91.93%   -0.57%     
- Complexity     2349     2360      +11     
============================================
  Files           246      247       +1     
  Lines          4891     4947      +56     
  Branches        519      530      +11     
============================================
+ Hits           4524     4548      +24     
- Misses          242      268      +26     
- Partials        125      131       +6     
Impacted Files Coverage Δ
...c/main/java/net/datafaker/providers/base/Text.java 66.66% <37.50%> (-24.25%) ⬇️
...rc/main/java/net/datafaker/providers/base/Aws.java 100.00% <100.00%> (ø)
.../net/datafaker/providers/movie/MovieProviders.java 100.00% <0.00%> (ø)
...n/java/net/datafaker/providers/movie/OnePiece.java 100.00% <0.00%> (ø)
.../main/java/net/datafaker/service/FakerContext.java 87.17% <0.00%> (+2.56%) ⬆️
src/main/java/net/datafaker/service/FakerIDN.java 72.72% <0.00%> (+9.09%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@snuyanzin snuyanzin merged commit fd8e32b into datafaker-net:main Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments