2009/5/26  <[email protected]>:
>
>
>
> On May 25, 4:10 pm, Erik Corry <[email protected]> wrote:
>> 2009/5/25  <[email protected]>:
>> > The good news is that string manipulation looked pretty fast -- 50,000
>> > looped regexes in a JS function passed to the V8 wrapper ran in about
>> > 0.19 seconds versus 0.14 seconds against our C++ PCRE wrapper. Not bad
>> > at all, very happy with that, as PCRE is known to be a very fast
>> > library with all kinds of speedup tricks.
>>
>> Actually I would have expected us to do better than that.  Care to
>> share your test?
>
> Sure. In a slightly larger scale test I created 250,000 strings of the
> form "00-00-0000", which are iterated through as dates, so I end up
> with "05-03-1667" through to "22-08-2351", for example. Then the
> following JS function is created and called...
>
> function regex_test(re){
>    return (re.replace(/^(\d\d)(\d\d)(\d{4})$/,'$3-$2-$1'));
> }
>
> ...using some code that looks quite like this (extracted/simplified
> from main program):
>
> const v8::Handle<v8::Object> exec_global = execution_context->Global
> ();
> const v8::Handle<v8::Function> js_func = v8::Handle<v8::Function>::Cast
> ( exec_global->Get(func_name) );
>
> for( int i=0; i<n_calls; i++ ){
>    v8::HandleScope loop_scope;
>    setArgvParams( i,ParamBlock );
>    v8::Handle<v8::Value> js_func_result = js_func->Call( exec_global,
> 1,argv );
>    // etc
> }

It seems likely that you are spending all your time setting up argv
and almost no time in the actual regexp here.  Also the strings to be
matched are all small so most of the 'regexp' time is spent going in
and out of the regexp matching code.  We could probably optimize that.

> I'm wondering if the code in setArgvParams can be improved. Everything
> is passed by ref into that block to instantiate the argv for Call; the
> only copy being done is to instantiate the v8::String object:
>
>    argv[j] = v8::String::New( Variant->asStr(),Variant->strLen() );
>
> I see something about an ExternalAsciiString in the v8.h header. Would
> this let me just provide a pointer to the existing string and avoid a
> copy? If so I can't really see how to use it in this way from the few
> fragments of code that I found. Possible? Would avoid a lot of
> unnecessary copies if so.

You could use ExternalAsciiString and that would certainly help, but
you would still be creating a new string object every time (it would
just be smaller because the actual characters were not in the JS
heap).  So your benchmark would still be a mixture of
allocation/collection and regexp.  Which is fine, you just need to
know what you are measuring.

> Will try some more complex math as sugegsted, and see what happens. I
> haven't used the profiler yet, will search for some docs/examples and
> see what that returns.

http://code.google.com/p/v8/wiki/V8Profiler
Let us know if anything is unclear.

-- 
Erik Corry, Software Engineer
Google Denmark ApS.  CVR nr. 28 86 69 84
c/o Philip & Partners, 7 Vognmagergade, P.O. Box 2227, DK-1018
Copenhagen K, Denmark.

--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to