amberjs 1.17.0

JavaScript/TypeScript runtime built with Rust and V8
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
// 运行时对比模块
//
// 提供与 Bun、Node.js 等运行时的性能对比功能

use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap};
use super::{BenchmarkError, BenchmarkResult, BenchmarkResult as Result, Runtime};
use std::time::{Duration, Instant};
use std::path::PathBuf;

/// 运行时检测器
#[derive(Debug)]
pub struct RuntimeDetector {
    /// 检测到的运行时
    detected_runtimes: HashMap<Runtime, bool>,
}
impl RuntimeDetector {
    /// 创建新的运行时检测器
    pub fn new() -> Self {
        let mut detector = Self {
            detected_runtimes: HashMap::new(),
        };
        detector.detect_all_runtimes();
        detector
    }
    /// 检测所有运行时
    pub fn detect_all_runtimes(&mut self) {
        // 检测 Amber
        self.detected_runtimes.insert(
            Runtime::Amber,
            check_command_available("amber")
        );
        // 检测 Node.js
        self.detected_runtimes.insert(
            Runtime::NodeJs,
            check_command_available("node")
        );
        // 检测 Bun
        self.detected_runtimes.insert(
            Runtime::Bun,
            check_command_available("bun")
        );
        // 检测 Deno
        self.detected_runtimes.insert(
            Runtime::Deno,
            check_command_available("deno")
        );
    }
    /// 检查特定运行时是否可用
    pub fn is_available(&self, runtime: Runtime) -> bool {
        self.detected_runtimes
            .get(&runtime)
            .cloned()
            .unwrap_or(false)
    }
    /// 获取所有可用的运行时
    pub fn get_available_runtimes(&self) -> Vec<Runtime> {
        self.detected_runtimes
            .iter()
            .filter_map(|(runtime, &available)| {
                if available {
                    Some(*runtime)
                } else {
                    None
                }
            })
            .collect()
    }
    /// 获取运行时版本
    pub fn get_version(&self, runtime: Runtime) -> Option<String> {
        match runtime {
            Runtime::Amber => get_command_version("amber"),
            Runtime::NodeJs => get_command_version("node"),
            Runtime::Bun => get_command_version("bun"),
            Runtime::Deno => get_command_version("deno"),
            Runtime::Custom(_) => None,
        }
    }
}
/// 进程启动器
#[derive(Debug)]
pub struct ProcessLauncher {
    /// 启动配置
    config: ProcessConfig,
}
impl ProcessLauncher {
    /// 创建新的进程启动器
    pub fn new(config: ProcessConfig) -> Self {
        Self { config }
    }
    /// 启动进程
    pub async fn launch(&self, code: &str, runtime: Runtime) -> Result<ProcessOutput> {
        let start_time: _ = tokio::time::Instant::now();
        match runtime {
            Runtime::Amber => {
                self.launch_amberjs(code).await
            }
            Runtime::NodeJs => {
                self.launch_nodejs(code).await
            }
            Runtime::Bun => {
                self.launch_bun(code).await
            }
            Runtime::Deno => {
                self.launch_deno(code).await
            }
            Runtime::Custom(_) => {
                Err(BenchmarkError::RuntimeNotAvailable(
                    "Custom runtime not supported".to_string())
            }
        }.map(|mut output| {
            output.elapsed_time = start_time.elapsed();
            output
        })
    }
    /// 启动 Amber 进程
    async fn launch_amberjs(&self, code: &str) -> Result<ProcessOutput> {
        let temp_file: _ = super::super::utils::create_temp_dir("amberjs_bench")?;
        let file_path: _ = temp_file.path().join("test.js");
        // 写入临时文件
        tokio::fs::write(&file_path, code).await?;
        // 启动进程
        let output: _ = tokio::process::Command::new("amber")
            .arg(&file_path)
            .output()
            .await?;
        let exit_code: _ = output.status.code().unwrap_or(-1);
        let stdout: _ = String::from_utf8_lossy(&output.stdout).to_string();
        let stderr: _ = String::from_utf8_lossy(&output.stderr).to_string();
        Ok(ProcessOutput {
            runtime: Runtime::Amber,
            exit_code,
            stdout,
            stderr,
            elapsed_time: tokio::time::Duration::from_secs(0),
        })
    }
    /// 启动 Node.js 进程
    async fn launch_nodejs(&self, code: &str) -> Result<ProcessOutput> {
        let temp_file: _ = super::super::utils::create_temp_dir("nodejs_bench")?;
        let file_path: _ = temp_file.path().join("test.js");
        tokio::fs::write(&file_path, code).await?;
        let output: _ = tokio::process::Command::new("node")
            .arg(&file_path)
            .output()
            .await?;
        let exit_code: _ = output.status.code().unwrap_or(-1);
        let stdout: _ = String::from_utf8_lossy(&output.stdout).to_string();
        let stderr: _ = String::from_utf8_lossy(&output.stderr).to_string();
        Ok(ProcessOutput {
            runtime: Runtime::NodeJs,
            exit_code,
            stdout,
            stderr,
            elapsed_time: tokio::time::Duration::from_secs(0),
        })
    }
    /// 启动 Bun 进程
    async fn launch_bun(&self, code: &str) -> Result<ProcessOutput> {
        let temp_file: _ = super::super::utils::create_temp_dir("bun_bench")?;
        let file_path: _ = temp_file.path().join("test.js");
        tokio::fs::write(&file_path, code).await?;
        let output: _ = tokio::process::Command::new("bun")
            .arg(&file_path)
            .output()
            .await?;
        let exit_code: _ = output.status.code().unwrap_or(-1);
        let stdout: _ = String::from_utf8_lossy(&output.stdout).to_string();
        let stderr: _ = String::from_utf8_lossy(&output.stderr).to_string();
        Ok(ProcessOutput {
            runtime: Runtime::Bun,
            exit_code,
            stdout,
            stderr,
            elapsed_time: tokio::time::Duration::from_secs(0),
        })
    }
    /// 启动 Deno 进程
    async fn launch_deno(&self, code: &str) -> Result<ProcessOutput> {
        let temp_file: _ = super::super::utils::create_temp_dir("deno_bench")?;
        let file_path: _ = temp_file.path().join("test.js");
        tokio::fs::write(&file_path, code).await?;
        let output: _ = tokio::process::Command::new("deno")
            .arg("run")
            .arg(&file_path)
            .output()
            .await?;
        let exit_code: _ = output.status.code().unwrap_or(-1);
        let stdout: _ = String::from_utf8_lossy(&output.stdout).to_string();
        let stderr: _ = String::from_utf8_lossy(&output.stderr).to_string();
        Ok(ProcessOutput {
            runtime: Runtime::Deno,
            exit_code,
            stdout,
            stderr,
            elapsed_time: tokio::time::Duration::from_secs(0),
        })
    }
}
/// 进程启动配置
#[derive(Debug, Clone)]
pub struct ProcessConfig {
    /// 超时时间
    pub timeout: tokio::time::Duration,
    /// 环境变量
    pub environment: HashMap<String, String>,
    /// 工作目录
    pub working_directory: Option<PathBuf>,
}
impl Default for ProcessConfig {
    fn default() -> Self {
        Self {
            timeout: tokio::time::Duration::from_secs(30),
            environment: HashMap::new(),
            working_directory: None,
        }
    }
}
impl ProcessConfig {
    /// 创建新的配置
    pub fn new() -> Self {
        Self::default()
    }
    /// 设置超时时间
    pub fn timeout(mut self, timeout: tokio::time::Duration) -> Self {
        self.timeout = timeout;
        self
    }
    /// 添加环境变量
    pub fn add_env(mut self, key: &str, value: &str) -> Self {
        self.environment.insert(key.to_string(), value.to_string());
        self
    }
    /// 设置工作目录
    pub fn working_directory(mut self, dir: PathBuf) -> Self {
        self.working_directory = Some(dir);
        self
    }
}
/// 进程输出
#[derive(Debug, Clone)]
pub struct ProcessOutput {
    /// 运行时类型
    pub runtime: Runtime,
    /// 退出码
    pub exit_code: i32,
    /// 标准输出
    pub stdout: String,
    /// 标准错误
    pub stderr: String,
    /// 执行时间
    pub elapsed_time: tokio::time::Duration,
}
impl ProcessOutput {
    /// 检查是否成功
    pub fn is_success(&self) -> bool {
        self.exit_code == 0
    }
    /// 获取执行时间 (毫秒)
    pub fn execution_time_ms(&self) -> f64 {
        self.elapsed_time.as_secs_f64() * 1000.0
    }
}
/// 对比报告
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ComparisonReport {
    /// 测试名称
    pub test_name: String,
    /// 基准运行时结果
    pub baseline_result: BenchmarkResult,
    /// 对比运行时结果
    pub comparison_results: Vec<BenchmarkResult>,
    /// 性能对比
    pub performance_comparison: PerformanceComparison,
    /// 统计显著性
    pub statistical_significance: StatisticalSignificance,
}
impl ComparisonReport {
    /// 创建新的对比报告
    pub fn new(test_name: &str, baseline_result: BenchmarkResult) -> Self {
        Self {
            test_name: test_name.to_string(),
            baseline_result,
            comparison_results: Vec::new(),
            performance_comparison: PerformanceComparison::default(),
            statistical_significance: StatisticalSignificance::default(),
        }
    }
    /// 添加对比结果
    pub fn add_comparison_result(&mut self, result: BenchmarkResult) {
        self.comparison_results.push(result);
    }
    /// 生成性能对比
    pub fn generate_performance_comparison(&mut self) {
        self.performance_comparison = PerformanceComparison::generate(
            &self.baseline_result,
            &self.comparison_results,
        );
    }
    /// 生成统计显著性分析
    pub fn generate_statistical_analysis(&mut self) {
        self.statistical_significance = StatisticalSignificance::analyze(
            &self.baseline_result,
            &self.comparison_results,
        );
    }
}
/// 性能对比
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct PerformanceComparison {
    /// 性能提升百分比
    pub improvements: Vec<PerformanceImprovement>,
    /// 吞吐量对比
    pub throughput_comparison: HashMap<Runtime, f64>,
    /// 延迟对比
    pub latency_comparison: HashMap<Runtime, f64>,
}
impl PerformanceComparison {
    /// 生成性能对比
    pub fn generate(
        baseline: &BenchmarkResult,
        comparisons: &[BenchmarkResult],
    ) -> Self {
        let mut improvements = Vec::new();
        let mut throughput_comparison = HashMap::new();
        let mut latency_comparison = HashMap::new();
        // 计算基准性能
        let baseline_throughput: _ = baseline.throughput();
        let baseline_latency: _ = baseline.average_duration().as_secs_f64() * 1000.0;
        for result in comparisons {
            // 计算性能提升
            let throughput_improvement: _ = if baseline_throughput > 0.0 {
                ((result.throughput() - baseline_throughput) / baseline_throughput) * 100.0
            } else {
                0.0
            };
            let latency_improvement: _ = if baseline_latency > 0.0 {
                ((baseline_latency - result.average_duration().as_secs_f64() * 1000.0) / baseline_latency) * 100.0
            } else {
                0.0
            };
            improvements.push(PerformanceImprovement {
                runtime: result.runtime,
                throughput_improvement,
                latency_improvement,
            });
            throughput_comparison.insert(result.runtime, result.throughput());
            latency_comparison.insert(result.runtime, result.average_duration().as_secs_f64() * 1000.0);
        }
        Self {
            improvements,
            throughput_comparison,
            latency_comparison,
        }
    }
}
/// 性能提升
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PerformanceImprovement {
    /// 运行时类型
    pub runtime: Runtime,
    /// 吞吐量提升百分比
    pub throughput_improvement: f64,
    /// 延迟提升百分比
    pub latency_improvement: f64,
}
/// 统计显著性
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct StatisticalSignificance {
    /// 显著性测试结果
    pub significance_tests: Vec<SignificanceTest>,
    /// 置信区间
    pub confidence_intervals: HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64), Runtime, (f64, f64), std::collections::HashMap<Runtime, (f64, f64), Runtime, (f64, f64)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>,
}
impl StatisticalSignificance {
    /// 分析统计显著性
    pub fn analyze(
        baseline: &BenchmarkResult,
        comparisons: &[BenchmarkResult],
    ) -> Self {
        let mut significance_tests = Vec::new();
        let mut confidence_intervals = HashMap::new();
        for result in comparisons {
            let is_significant: _ = baseline.is_statistically_significant(result, 0.05);
            significance_tests.push(SignificanceTest {
                runtime: result.runtime,
                is_significant,
                p_value: 0.0, // 简化实现
            });
            confidence_intervals.insert(
                result.runtime,
                (
                    result.statistics.confidence_interval_lower.as_secs_f64() * 1000.0,
                    result.statistics.confidence_interval_upper.as_secs_f64() * 1000.0,
                )
            );
        }
        Self {
            significance_tests,
            confidence_intervals,
        }
    }
}
/// 显著性测试
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SignificanceTest {
    /// 运行时类型
    pub runtime: Runtime,
    /// 是否显著
    pub is_significant: bool,
    /// P 值
    pub p_value: f64,
}
/// 检查命令是否可用
fn check_command_available(command: &str) -> bool {
    Command::new(command)
        .arg("--version")
        .output()
        .map(|output| output.status.success())
        .unwrap_or(false)
}
/// 获取命令版本
fn get_command_version(command: &str) -> Option<String> {
    let output: _ = Command::new(command)
        .arg("--version")
        .output()
        .ok()?;
    if output.status.success() {
        Some(String::from_utf8_lossy(&output.stdout).trim().to_string())
    } else {
        None
    }
}
#[cfg(test)]
mod tests {
    #[test]
    fn test_runtime_detection() {
        let detector: _ = RuntimeDetector::new();
        let available: _ = detector.get_available_runtimes();
        println!("Available runtimes: {:?}", available);
    }
    #[tokio::test]
    async fn test_process_launcher() {
        let config: _ = ProcessConfig::new();
        let launcher: _ = ProcessLauncher::new(config);
        let code: _ = r#"
            console.log('Hello, World!');
            const start = Date.now();
            // 模拟一些计算
            let sum: _ = 0;
            for (let i: _ = 0; i < 1000000; i++) {
                sum += i;
            }
            const end = Date.now();
            console.log('Time:', end - start, 'ms');
        "#;
        let output: _ = launcher.launch(code, Runtime::NodeJs).await.unwrap();
        println!("Output: {}", output.stdout);
        println!("Time: {} ms", output.execution_time_ms());
    }
}