<https://lh6.googleusercontent.com/-sPNEtxGhqEc/VI6531u4HQI/AAAAAAAAAHw/2rZtAitF4bM/s1600/Screenshot%2Bfrom%2B2014-12-15%2B18%3A10%3A09.png>
My Os is fedora20, v8 version is v8-3.25.30, 
first loop consumes 0.02 second, and then the 172th's loop consumes 
2.48second.

#include <pthread.h>
#include <v8.h>
#include <sys/time.h>

double GetTime()
{
    timeval tv;
    gettimeofday(&tv, NULL);
    return tv.tv_sec + (double)tv.tv_usec * 0.000001;
}

v8::Isolate *isolate;

class Thread
{
    public:
        static void* Start(void *thread)
        {
            static_cast<Thread*>(thread)->Start_();
        }
    private:
        void Start_()
        {
            v8::Locker locker(isolate);
            v8::Isolate::Scope scope(isolate);
        }

};

void test(pthread_t tid[], Thread thread[])
{
    for (int i = 0; i < 1024; ++i)
    {
        pthread_create(&tid[i], NULL, Thread::Start, &thread[i]);
    }
    for (int i = 0; i < 1024; ++i)
    {
        pthread_join(tid[i], NULL);
    }
}

int main(int argc, char* argv[])
{
    v8::V8::Initialize();
    isolate = v8::Isolate::New();
    {
        pthread_t tid[1024];
        Thread thread[1024];
        for (int i = 0; i < 1000 * 1000 * 1000; ++i)
        {
            double s = GetTime();
            test(tid, thread);
            printf("%d. %f\n", i+1, GetTime() - s);
        }
    }
    isolate->Dispose();
    v8::V8::Dispose();
}

-- 
-- 
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- 
You received this message because you are subscribed to the Google Groups 
"v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to