// V8 single end-to-end cold start benchmark // // Measures: process start → V8 init → Isolate → Context → eval → exit // // Build: cmake --build build/release --target bench-v8-e2e // Usage: ./bench-v8-e2e #include #include #include #include #include using namespace v8; class Timer { public: Timer() { start(); } void start() { start_ = std::chrono::high_resolution_clock::now(); } double elapsedMs() const { auto now = std::chrono::high_resolution_clock::now(); return std::chrono::duration(now - start_).count(); } private: std::chrono::high_resolution_clock::time_point start_; }; int main(int argc, char* argv[]) { Timer totalTimer; // Initialize V8 V8::InitializeICUDefaultLocation(argv[0]); V8::InitializeExternalStartupData(argv[0]); std::unique_ptr platform = platform::NewDefaultPlatform(); V8::InitializePlatform(platform.get()); V8::Initialize(); double initTime = totalTimer.elapsedMs(); // Create Isolate Isolate::CreateParams create_params; create_params.array_buffer_allocator = ArrayBuffer::Allocator::NewDefaultAllocator(); Isolate* isolate = Isolate::New(create_params); double isolateTime = totalTimer.elapsedMs(); { Isolate::Scope isolate_scope(isolate); HandleScope handle_scope(isolate); // Create Context Local context = Context::New(isolate); double contextTime = totalTimer.elapsedMs(); Context::Scope context_scope(context); // Eval simple script Local source = String::NewFromUtf8Literal(isolate, "var x = 0; for (var i = 0; i < 1000; i++) x += i; x"); TryCatch try_catch(isolate); Local