All Projects → bgadrian → fastfaker

bgadrian / fastfaker

Licence: GPL-3.0 license
Fast, concurrent fake data generator for any structure or type.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to fastfaker

Faker.js
generate massive amounts of realistic fake data in Node.js and the browser
Stars: ✭ 34,329 (+163371.43%)
Mutual labels:  faker, faker-generator
strgen
A Python module for a template language that generates randomized data
Stars: ✭ 34 (+61.9%)
Mutual labels:  random, randomizer
SharpLoader
🔮 [C#] Source code randomizer and compiler
Stars: ✭ 36 (+71.43%)
Mutual labels:  random, randomizer
Random
Generate random strings or numeric values
Stars: ✭ 68 (+223.81%)
Mutual labels:  random, faker
random
Random data generator AKA faker
Stars: ✭ 14 (-33.33%)
Mutual labels:  random, faker
blaver
A JavaScript library built on top of the Faker.JS library. It generates massive amounts of fake data in the browser and node.js.
Stars: ✭ 112 (+433.33%)
Mutual labels:  faker, faker-generator
jRand
A Java library to generate random data for all sorts of things. Java random data faker
Stars: ✭ 27 (+28.57%)
Mutual labels:  random, faker
fake-web-events
Creates a Simulation of Fake Web Events
Stars: ✭ 48 (+128.57%)
Mutual labels:  faker, faker-generator
faker
Random fake data and struct generator for Go.
Stars: ✭ 67 (+219.05%)
Mutual labels:  random, faker
awesome-randomizers
🎲 A curated list of awesome services for obtaining random results.
Stars: ✭ 36 (+71.43%)
Mutual labels:  random, randomizer
jedi-faker
Faker extension for Star Wars junkie
Stars: ✭ 15 (-28.57%)
Mutual labels:  faker, faker-generator
mkjson
A commandline tool to generate static or random JSON records
Stars: ✭ 16 (-23.81%)
Mutual labels:  faker, faker-generator
randomdata
TYPO3 extensions to generate new random data or replace existing data with random data
Stars: ✭ 14 (-33.33%)
Mutual labels:  random, faker
FakerDotNet
A .NET port of the Ruby faker gem
Stars: ✭ 15 (-28.57%)
Mutual labels:  faker, faker-library
faker
A set of javascript packages that generates fake data for you.
Stars: ✭ 33 (+57.14%)
Mutual labels:  faker, faker-generator
test-util
👓 Provides utilities for tests.
Stars: ✭ 15 (-28.57%)
Mutual labels:  faker
util
封装了一些Java常用的功能
Stars: ✭ 19 (-9.52%)
Mutual labels:  random
playlist-randomizer
A small React app that makes use of Redux, React Router and Material UI
Stars: ✭ 32 (+52.38%)
Mutual labels:  randomizer
RNG
A simple state-of-the-art C++ random number generator
Stars: ✭ 19 (-9.52%)
Mutual labels:  random
faker
Generate massive amounts of fake data in the browser and node.js
Stars: ✭ 6,940 (+32947.62%)
Mutual labels:  faker

Fast Faker Go Report Card GoDoc Build Status codecov contributions

FastFaker is a data generator written in go. It can generate over 50 data types and has 2 modes of operation: fast or (concurrent) safe.

Features

  • Every function has an example and a benchmark, see benchmarks
  • Zero dependencies (no external calls, no vendor, dep or modules required)
  • Randomizes user defined structs
  • Over 130 functions for regular use
  • Templates with over 110 variables
  • Extensible
  • Concurrent safe
  • Go 1.x compatibility
  • Performance
  • Idiomatic Go
  • predefined popular structures (Address, Person ...)
  • 200 unit tests and examples

130+ Functions!!!

If there is something that is generic enough missing from this package let me know!

How to use

Library

The package is meant to be used as a Go package, and imported in your own application, but it can be used as an app or service too:

Utility

A small example is provided as an example, and can be used as a binary standalone utility, after compilation:

$ go build -o fastfaker example/standalone-template/main.go
$ ./fastfaker '{name}'
$ Victoria Berge

Web service

If you do not want to spend time importing this library in your project, or you are using a different programming language, you can use the Pseudoservice microservice. It is a HTTP Web sever wrapper on the Templates functionality.

docker run --name pseudoservice -p 8080:8080 -d -e APIKEY=MYSECRET bgadrian/pseudoservice
curl "http://localhost:8080/custom/1?token=MYSECRET&template=~name~"
{"results":["Jefferey Koch"],"seed":-4329827746951412836}

Documentation

All the public functions have comments, examples, tests and benchmarks: https://godoc.org/github.com/bgadrian/fastfaker/faker

You can find more examples in the Example folder.

Example

	faker.Global.Name()             // Markus Moen
	faker.Global.Email()            // [email protected]
	faker.Global.Phone()            // (570)245-7485
	faker.Global.BS()               // front-end
	faker.Global.BeerName()         // Duvel
	faker.Global.Color()            // MediumOrchid
	faker.Global.Company()          // Moen, Pagac and Wuckert
	faker.Global.CreditCardNumber() // 4287271570245748
	faker.Global.HackerPhrase()     // Connecting the array won't do anything, we need to generate the haptic COM driver!
	faker.Global.JobTitle()         // Director
	faker.Global.PasswordFull()     // +eHQa02X9n3X
	faker.Global.CurrencyShort()    // USD
	// 130+ more!!!

	// Create structs with random injected data
	type Foo struct {
		Browser string `fake:"{browser}"`
		Name    string `fake:"{beername}"`
		Int     int
		Dice    uint8
		Pointer *int
		Skip    *string `fake:"skip"`
	}
	var f Foo
	faker.Global.Struct(&f)
	fmt.Printf("%s\n", f.Browser)  //firefox
	fmt.Printf("%s\n", f.Name)     //Samuel Smith’s Oatmeal Stout
	fmt.Printf("%d\n", f.Int)      //-3651589698752897048
	fmt.Printf("%d\n", f.Dice)     //62
	fmt.Printf("%d\n", *f.Pointer) //-8819218091111228151
	fmt.Printf("%v\n", f.Skip)     //<nil>

Faker types, concurrency and performance

Fast Faker has 2 modes of operating: safe or fast.

Safe

faker.Global and instances of NewSafeFaker() are safe to be used from multiple goroutines, but has a small overhead. Similar with rand.* global functions it uses a mutex.

Advantage: easy to use, safe.

Fast

Another way of using faker is having one Faker instance for each goroutine.

go func(){
    myOwnFaker := faker.NewFastFaker()
    
    myOwnFaker.Name() // Markus Moen
    myOwnFaker.Email() // [email protected]
}()

Advantage: performance

For a heavy usage in a 4 CPU env, the performance benefits of the FastFaker can be up to 10x:

go test -benchmem  -bench=BenchmarkNew* github.com/bgadrian/fastfaker/faker
goos: linux
goarch: amd64
pkg: github.com/bgadrian/fastfaker/faker
BenchmarkNewSafeFaker_Parallel-4          500000              2668 ns/op               0 B/op          0 allocs/op
BenchmarkNewFastFaker_Parallel-4        10000000               225 ns/op               0 B/op          0 allocs/op

Templates

Template is the most powerful FastFaker feature. It allows custom patterns/templates (JSON, YAML, HTML, ...) of text to be filled with over 110 random types of data (variables).

It can be used directly (faker.Template* methods) or via the faker.Struct fill method and fake: tags.

//instead of:
fmt.Sprintf("I'm %s, call me at %s!", fastFaker.Name(), fastFaker.Numerify("###-###-####"))
//you can do:
fastFaker.Template("I'm {name}, call me at ###-###-####!") // I'm John, call me at 152-335-8761!

You can use any type of texts, formats, encoded or not (HTML, JSON, YAML, configs ...). For more details see the TEMPLATES section

/Data godoc

If you want to use the raw data that the Faker uses internally (like Names, Streets, Countries and Companies) you can import the Data package directly, see its documentation.

/Randomizer godoc

The pseudo-data generator has its own package. At its core it is a rand.* wrapper with more functions.

gofakeit

This library started as a fork of gofakeit, but I had different requirements from such a library, in particular performance and extensibility and could not guarantee backward compatibility. Future sync will be performed between the projects.

How is FastFaker different?

  • performance (up to 10x improvement)
  • code quality (fixed over 50 gometalinter warnings)
  • Templates
  • error logger (stdErr) instead of silent fails
  • new functions
  • more documentation, new examples and tests
  • usage, instead of gofakeit.Name() the calls are faker.Global.Name() or faker.NewFastFaker().Name()
  • fastfaker uses the semantic version, making it compatible with go modules
  • split /data and /randomizer into their own packages
  • version gofakeit 3.x is fastfaker 1.x
  • version gofakeit features are brought in fastfaker 2.1
  • more in the changelog

Change log

All the major changes are found in the CHANGELOG.

Benchmarks

For a quick overview see BENCHMARKS.md.

Contributing

For more info see the contributing readme

TODO

See issues

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].