Giter VIP home page Giter VIP logo

Comments (5)

Drulac avatar Drulac commented on May 14, 2024

I made this little code to try perf on a method :

var gpu = new GPU();

var add = gpu.createKernel(function(){
    var a = 0;
    for(var i=0; i < 100000000000; ++i)
    {
        if(i < 100)
        {
            a = a + 1;
        }else{
            break;
        }
    }
    return a;
}).dimensions([1]);

function bench()
{
    add.mode("GPU");
    console.time("GPU");
    console.log(add());
    console.timeEnd("GPU");

    add.mode("CPU");
    console.time("CPU");
    console.log(add());
    console.timeEnd("CPU");
}

bench result :

bench();
GPU: 107.860ms
CPU: 3.080ms
bench();
GPU: 2.212ms
CPU: 2.339ms
bench();
GPU: 1.749ms
CPU: 2.439ms
bench();
GPU: 1.607ms
CPU: 2.013ms
bench();
GPU: 1.963ms
CPU: 2.250ms

from gpu.js.

fuzzie360 avatar fuzzie360 commented on May 14, 2024

@PicoCreator we already have loops with variables

var add = gpu.createKernel(function(){
    var a = 0; var b = 100;
    for(var i=0; i < b; i++)
    {
        a = a + 1;
    }
    return a;
}).dimensions([1]).loopMaxIterations(100000000000);

function bench()
{
    add.mode("GPU");
    console.time("GPU");
    console.log(add());
    console.timeEnd("GPU");

    add.mode("CPU");
    console.time("CPU");
    console.log(add());
    console.timeEnd("CPU");
}

from gpu.js.

PicoCreator avatar PicoCreator commented on May 14, 2024

@fuzzie360 bows

@Drulac, would that be good enough? : Now you just need to be able to create fixed arrays in GPU/JS code right?

from gpu.js.

Drulac avatar Drulac commented on May 14, 2024

This doesn't work I think (I havent the time to test)

var add = gpu.createKernel(function(b){
    var a = 0;
    for(var i=0; i < b; i++)
    {
        a = a + 1;
    }
    return a;
}).dimensions([1]).loopMaxIterations(100000000000);

function bench()
{
    add.mode("GPU");
    console.time("GPU");
    console.log(add(100));
    console.timeEnd("GPU");

    add.mode("CPU");
    console.time("CPU");
    console.log(add(100));
    console.timeEnd("CPU");
}

from gpu.js.

fuzzie360 avatar fuzzie360 commented on May 14, 2024

Closing this issue because the code snippet works fine now

from gpu.js.

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.