Code Monkey home page Code Monkey logo

Comments (7)

vmihailenco avatar vmihailenco commented on July 22, 2024

I have an idea how to improve BenchmarkPgSelectMultipleRowsPrepared and BenchmarkPgSelectMultipleRowsUnprepared (base on fields that bypass a lot reflect work: https://github.com/vmihailenco/msgpack/blob/master/typeinfo.go#L20). BenchmarkRawSelectMultipleRowsPrepared looks like a cheating and TBH I don't understand what it does. The rest of benchmarks looks good :)

from pg.

aktau avatar aktau commented on July 22, 2024

Well, it's documented that the raw methods are basically cheating in order to determine a lower bound to the attainable results. Pretty clever: https://github.com/jackc/go_db_bench

from pg.

vmihailenco avatar vmihailenco commented on July 22, 2024

What I found so far is that changing people to:

type People []person

func (people *People) New() interface{} {
    pp := *people
    pp = append(pp, person{})
    return &pp[len(pp)-1]
}

makes some benchmarks almost 30-40% faster. So I guess it is possible to write such benchmarks where go-pg will be much faster...

from pg.

aktau avatar aktau commented on July 22, 2024

I've actually always wondered why you used slices of pointers instead of just slices. Good to know!

from pg.

aktau avatar aktau commented on July 22, 2024

Wait, shouldn't it be:

type People []person

func (people *People) New() interface{} {
    p := person{}
    *people = append(*people,p)
    return &p
}

Because otherwise you append to a new slice (which refers to the same memory, which might get reallocated), and the old slice doesn't get updated.

Unless I'm misunderstanding something.

from pg.

aktau avatar aktau commented on July 22, 2024

Disregard me, that didn't work because it returned a copy of person{}... ugh. This is the corrected version:

*people = append(*people, person{})
dpeople := *people
return &dpeople[len(dpeople)-1]

What do you think?

from pg.

vmihailenco avatar vmihailenco commented on July 22, 2024

I consider this fixed by jackc/go_db_bench#2. go-pg is still slightly slower, but that is the cost of using reflect.

from pg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.