@@ -2,48 +2,62 @@ import path from 'node:path';
22import { withCodSpeed } from '@codspeed/tinybench-plugin' ;
33import { Bench } from 'tinybench' ;
44import { exec } from 'tinyexec' ;
5- import { renderPages } from '../make-project/render-default.js' ;
65import { astroBin } from './_util.js' ;
76
87export async function run ( { memory : _memory , render, stress : _stress } ) {
98 const options = {
109 iterations : 10 ,
1110 } ;
1211 const bench = process . env . CODSPEED ? withCodSpeed ( new Bench ( options ) ) : new Bench ( options ) ;
13- let app ;
14- bench . add (
15- 'Rendering' ,
16- async ( ) => {
12+ await exec ( astroBin , [ 'build' ] , {
13+ nodeOptions : {
14+ cwd : render . root ,
15+ stdio : 'inherit' ,
16+ } ,
17+ } ) ;
18+
19+ const entry = new URL ( './dist/server/entry.mjs' , `file://${ render . root } ` ) ;
20+ const { manifest, createApp } = await import ( entry ) ;
21+ const streamingApp = createApp ( manifest , true ) ;
22+ const nonStreamingApp = createApp ( manifest , false ) ;
23+ bench
24+ . add ( 'Rendering: streaming [true], .astro file' , async ( ) => {
1725 console . info ( 'Start task.' ) ;
18- const result = { } ;
19- for ( const fileName of renderPages ) {
20- const pathname = '/' + fileName . slice ( 0 , - path . extname ( fileName ) . length ) ;
21- const request = new Request ( new URL ( pathname , 'http://exmpale.com' ) ) ;
22- const response = await app . render ( request ) ;
23- const html = await response . text ( ) ;
24- if ( ! result [ pathname ] ) result [ pathname ] = [ ] ;
25- result [ pathname ] . push ( html ) ;
26- }
26+ const request = new Request ( new URL ( 'http://exmpale.com/astro' ) ) ;
27+ await streamingApp . render ( request ) ;
2728 console . info ( 'Finish task.' ) ;
28- return result ;
29- } ,
30- {
31- async beforeAll ( ) {
32- // build for rendering
33- await exec ( astroBin , [ 'build' ] , {
34- nodeOptions : {
35- cwd : render . root ,
36- stdio : 'inherit' ,
37- } ,
38- } ) ;
29+ } )
30+ . add ( 'Rendering: streaming [true], .md file' , async ( ) => {
31+ console . info ( 'Start task.' ) ;
32+ const request = new Request ( new URL ( 'http://exmpale.com/md' ) ) ;
33+ await streamingApp . render ( request ) ;
34+ console . info ( 'Finish task.' ) ;
35+ } )
36+ . add ( 'Rendering: streaming [true], .mdx file' , async ( ) => {
37+ console . info ( 'Start task.' ) ;
38+ const request = new Request ( new URL ( 'http://exmpale.com/mdx' ) ) ;
39+ await streamingApp . render ( request ) ;
40+ console . info ( 'Finish task.' ) ;
41+ } )
3942
40- const entry = new URL ( './dist/server/entry.mjs' , `file://${ render . root } ` ) ;
41- const { manifest, createApp } = await import ( entry ) ;
42- app = createApp ( manifest ) ;
43- app . manifest = manifest ;
44- } ,
45- } ,
46- ) ;
43+ . add ( 'Rendering: streaming [false], .astro file' , async ( ) => {
44+ console . info ( 'Start task.' ) ;
45+ const request = new Request ( new URL ( 'http://exmpale.com/astro' ) ) ;
46+ await nonStreamingApp . render ( request ) ;
47+ console . info ( 'Finish task.' ) ;
48+ } )
49+ . add ( 'Rendering: streaming [false], .md file' , async ( ) => {
50+ console . info ( 'Start task.' ) ;
51+ const request = new Request ( new URL ( 'http://exmpale.com/md' ) ) ;
52+ await nonStreamingApp . render ( request ) ;
53+ console . info ( 'Finish task.' ) ;
54+ } )
55+ . add ( 'Rendering: streaming [false], .mdx file' , async ( ) => {
56+ console . info ( 'Start task.' ) ;
57+ const request = new Request ( new URL ( 'http://exmpale.com/mdx' ) ) ;
58+ await nonStreamingApp . render ( request ) ;
59+ console . info ( 'Finish task.' ) ;
60+ } ) ;
4761
4862 await bench . run ( ) ;
4963 console . table ( bench . table ( ) ) ;
0 commit comments