Skip to content

Instantly share code, notes, and snippets.

@Arkiant
Last active September 9, 2019 08:22
Show Gist options
  • Save Arkiant/f116e43fbb554bfb24e78d779a3cfd0f to your computer and use it in GitHub Desktop.
Save Arkiant/f116e43fbb554bfb24e78d779a3cfd0f to your computer and use it in GitHub Desktop.

Revisions

  1. Arkiant revised this gist Sep 9, 2019. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions uuid_test.go
    Original file line number Diff line number Diff line change
    @@ -22,8 +22,8 @@ import (
    // github.com/sony/sonyflake 20f8707d600010 ~6 bytes of time (10 ms) + 1 byte sequence + 2 bytes machine id
    // github.com/segmentio/ksuid 0pPKHjWprnVxGH7dEsAoXX2YQv 4 bytes of time (seconds) + 16 random bytes
    // https://github.com/lithammer/shortuuid dwRQAc68PhHQh4BUnrNsoS UUIDv4 or v5, encoded in a more compact way
    // github.com/marstr/guid f47ac10b-58cc-0372-8567-0e02b2c3d479 -
    // github.com/teris-io/shortid ulATDpcWgN -
    // github.com/marstr/guid f47ac10b-58cc-0372-8567-0e02b2c3d479 -
    // github.com/teris-io/shortid ulATDpcWgN - -

    // PC
    // -----------------------------------------------------------------------------------------------------------------------------------------------------------
    @@ -38,7 +38,7 @@ import (
    // BenchmarkSegmentioUUID-8 5000000 284 ns/op 0 B/op 0 allocs/op
    // BenchmarkLithammerShortuuid-8 200000 6905 ns/op 2953 B/op 136 allocs/op
    // BenchmarkMarstrGuuid-8 3000000 540 ns/op 32 B/op 2 allocs/op
    // BenchmarkTerisIOShortid-8 1000000 1203 ns/op 311 B/op 11 allocs/op
    // BenchmarkTerisIOShortid-8 1000000 1203 ns/op 311 B/op 11 allocs/op

    func BenchmarkGoogleUUID(b *testing.B) {
    b.ReportAllocs()
  2. Arkiant revised this gist Sep 9, 2019. 1 changed file with 15 additions and 1 deletion.
    16 changes: 15 additions & 1 deletion uuid_test.go
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,8 @@ import (
    "github.com/google/uuid"

    "github.com/marstr/guid"

    "github.com/teris-io/shortid"
    )

    // Performance test to choose a uuid library
    @@ -20,7 +22,8 @@ import (
    // github.com/sony/sonyflake 20f8707d600010 ~6 bytes of time (10 ms) + 1 byte sequence + 2 bytes machine id
    // github.com/segmentio/ksuid 0pPKHjWprnVxGH7dEsAoXX2YQv 4 bytes of time (seconds) + 16 random bytes
    // https://github.com/lithammer/shortuuid dwRQAc68PhHQh4BUnrNsoS UUIDv4 or v5, encoded in a more compact way
    // github.com/marstr/guid f47ac10b-58cc-0372-8567-0e02b2c3d479 -
    // github.com/marstr/guid f47ac10b-58cc-0372-8567-0e02b2c3d479 -
    // github.com/teris-io/shortid ulATDpcWgN -

    // PC
    // -----------------------------------------------------------------------------------------------------------------------------------------------------------
    @@ -35,6 +38,7 @@ import (
    // BenchmarkSegmentioUUID-8 5000000 284 ns/op 0 B/op 0 allocs/op
    // BenchmarkLithammerShortuuid-8 200000 6905 ns/op 2953 B/op 136 allocs/op
    // BenchmarkMarstrGuuid-8 3000000 540 ns/op 32 B/op 2 allocs/op
    // BenchmarkTerisIOShortid-8 1000000 1203 ns/op 311 B/op 11 allocs/op

    func BenchmarkGoogleUUID(b *testing.B) {
    b.ReportAllocs()
    @@ -46,6 +50,16 @@ func BenchmarkGoogleUUID(b *testing.B) {
    }
    }

    func BenchmarkTerisIOShortid(b *testing.B) {
    b.ReportAllocs()
    for i := 0; i < b.N; i++ {
    _, err := shortid.Generate()
    if err != nil {
    b.Errorf("Error generating uuid with google/uuid: %v", err)
    }
    }
    }

    func BenchmarkSonyflakeUUID(b *testing.B) {
    b.ReportAllocs()
    for i := 0; i < b.N; i++ {
  3. Arkiant revised this gist Sep 6, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion uuid_test.go
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ import (
    // github.com/sony/sonyflake 20f8707d600010 ~6 bytes of time (10 ms) + 1 byte sequence + 2 bytes machine id
    // github.com/segmentio/ksuid 0pPKHjWprnVxGH7dEsAoXX2YQv 4 bytes of time (seconds) + 16 random bytes
    // https://github.com/lithammer/shortuuid dwRQAc68PhHQh4BUnrNsoS UUIDv4 or v5, encoded in a more compact way
    // github.com/marstr/guid f47ac10b-58cc-0372-8567-0e02b2c3d479 -
    // github.com/marstr/guid f47ac10b-58cc-0372-8567-0e02b2c3d479 -

    // PC
    // -----------------------------------------------------------------------------------------------------------------------------------------------------------
  4. Arkiant revised this gist Sep 6, 2019. 1 changed file with 17 additions and 5 deletions.
    22 changes: 17 additions & 5 deletions uuid_test.go
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,8 @@ import (
    "github.com/sony/sonyflake"

    "github.com/google/uuid"

    "github.com/marstr/guid"
    )

    // Performance test to choose a uuid library
    @@ -18,19 +20,21 @@ import (
    // github.com/sony/sonyflake 20f8707d600010 ~6 bytes of time (10 ms) + 1 byte sequence + 2 bytes machine id
    // github.com/segmentio/ksuid 0pPKHjWprnVxGH7dEsAoXX2YQv 4 bytes of time (seconds) + 16 random bytes
    // https://github.com/lithammer/shortuuid dwRQAc68PhHQh4BUnrNsoS UUIDv4 or v5, encoded in a more compact way
    // github.com/marstr/guid f47ac10b-58cc-0372-8567-0e02b2c3d479 -

    // PC
    // -----------------------------------------------------------------------------------------------------------------------------------------------------------
    // Windows 10 Enterprise 64 bits
    // Processor: i5-8250 CPU @ 1.60GHz 1.80GHz
    // Memory RAM: 8,00GB
    // Memory RAM: 8,00GB

    // Results
    // -----------------------------------------------------------------------------------------------------------------------------------------------------------
    // BenchmarkGoogleUUID-8 5000000 283 ns/op 16 B/op 1 allocs/op
    // BenchmarkSonyflakeUUID-8 1000 2400560 ns/op 18849 B/op 72 allocs/op
    // BenchmarkSegmentioUUID-8 5000000 285 ns/op 0 B/op 0 allocs/op
    // BenchmarkLithammerShortuuid-8 200000 6815 ns/op 2953 B/op 136 allocs/op
    // BenchmarkGoogleUUID-8 5000000 281 ns/op 16 B/op 1 allocs/op
    // BenchmarkSonyflakeUUID-8 500 2278076 ns/op 18851 B/op 72 allocs/op
    // BenchmarkSegmentioUUID-8 5000000 284 ns/op 0 B/op 0 allocs/op
    // BenchmarkLithammerShortuuid-8 200000 6905 ns/op 2953 B/op 136 allocs/op
    // BenchmarkMarstrGuuid-8 3000000 540 ns/op 32 B/op 2 allocs/op

    func BenchmarkGoogleUUID(b *testing.B) {
    b.ReportAllocs()
    @@ -71,3 +75,11 @@ func BenchmarkLithammerShortuuid(b *testing.B) {
    }

    }

    func BenchmarkMarstrGuuid(b *testing.B) {
    b.ReportAllocs()
    for i := 0; i < b.N; i++ {
    guid.NewGUID()
    }

    }
  5. Arkiant created this gist Sep 5, 2019.
    73 changes: 73 additions & 0 deletions uuid_test.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,73 @@
    package benchuuid

    import (
    "testing"

    "github.com/lithammer/shortuuid"

    "github.com/segmentio/ksuid"

    "github.com/sony/sonyflake"

    "github.com/google/uuid"
    )

    // Performance test to choose a uuid library
    // -----------------------------------------------------------------------------------------------------------------------------------------------------------
    // https://github.com/google/uuid c01d7cf6-ec3f-47f0-9556-a5d6e9009a43 UUIDv4
    // github.com/sony/sonyflake 20f8707d600010 ~6 bytes of time (10 ms) + 1 byte sequence + 2 bytes machine id
    // github.com/segmentio/ksuid 0pPKHjWprnVxGH7dEsAoXX2YQv 4 bytes of time (seconds) + 16 random bytes
    // https://github.com/lithammer/shortuuid dwRQAc68PhHQh4BUnrNsoS UUIDv4 or v5, encoded in a more compact way

    // PC
    // -----------------------------------------------------------------------------------------------------------------------------------------------------------
    // Windows 10 Enterprise 64 bits
    // Processor: i5-8250 CPU @ 1.60GHz 1.80GHz
    // Memory RAM: 8,00GB

    // Results
    // -----------------------------------------------------------------------------------------------------------------------------------------------------------
    // BenchmarkGoogleUUID-8 5000000 283 ns/op 16 B/op 1 allocs/op
    // BenchmarkSonyflakeUUID-8 1000 2400560 ns/op 18849 B/op 72 allocs/op
    // BenchmarkSegmentioUUID-8 5000000 285 ns/op 0 B/op 0 allocs/op
    // BenchmarkLithammerShortuuid-8 200000 6815 ns/op 2953 B/op 136 allocs/op

    func BenchmarkGoogleUUID(b *testing.B) {
    b.ReportAllocs()
    for i := 0; i < b.N; i++ {
    _, err := uuid.NewRandom()
    if err != nil {
    b.Errorf("Error generating uuid with google/uuid: %v", err)
    }
    }
    }

    func BenchmarkSonyflakeUUID(b *testing.B) {
    b.ReportAllocs()
    for i := 0; i < b.N; i++ {
    sf := sonyflake.NewSonyflake(sonyflake.Settings{})
    _, err := sf.NextID()
    if err != nil {
    b.Errorf("Error generating uuid with google/uuid: %v", err)
    }
    }
    }

    func BenchmarkSegmentioUUID(b *testing.B) {
    b.ReportAllocs()
    for i := 0; i < b.N; i++ {
    _, err := ksuid.NewRandom()
    if err != nil {
    b.Errorf("Error generating uuid with google/uuid: %v", err)
    }
    }

    }

    func BenchmarkLithammerShortuuid(b *testing.B) {
    b.ReportAllocs()
    for i := 0; i < b.N; i++ {
    shortuuid.New()
    }

    }