Skip to content

Commit 8428a15

Browse files
Hussein NasserHussein Nasser
authored andcommitted
add IP timeEnd
1 parent f287340 commit 8428a15

6 files changed

+19
-5
lines changed

23-performance/230-nextticks.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
//next tick happens after initial phase,
22
//a nice way to know when does next tick starts is when the initial phase done
3+
4+
console.time("IP")
5+
process.nextTick( () => console.timeEnd("IP"));
36
process.nextTick( ()=>console.log("TRUE END OF INITIAL PHASE--First next tick! "))
47

58
console.time('require Time');
@@ -15,6 +18,6 @@ for ( i =0; i< 1000000000; i++);
1518
process.nextTick( ()=>console.log("next tick1"))
1619
process.nextTick( ()=>console.log("next tick2"))
1720
process.nextTick( ()=>console.log("next tick3"))
18-
for ( i =0; i< 100000000000000; i++);
21+
for ( i =0; i< 1000000000; i++);
1922
console.log("end initial...")
2023

23-performance/231-promises-blocking-initial.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
//execution of the promise happens in the initial phase
22
//the resolve callback is executed in the next tick
33
//we are still blocking io.. (io executed last)
4+
console.time("IP")
5+
process.nextTick( () => console.timeEnd("IP"));
46
process.nextTick( ()=>console.log("---TRUE END OF INITIAL PHASE--First next tick! "))
57
console.log("initial phase start...")
68
console.log ("Invoking promise then ")
79
ExpensivePromise().then(x=>console.log("Got result promise " + x ))
810
const fs = require("fs")
9-
fs.readFile ( __filename , ()=> console.log( "IO executed."))
10-
for (let j =0; j< 5_000_000_000; j++);
11+
fs.readFile ( __filename , ()=> console.log( "IO executed. (poll phase)"))
12+
for (let j =0; j< 5_000_000; j++);
1113
console.log("end initial phase...")
1214
process.nextTick( ()=>console.log("next tick"))
1315
setTimeout (() => console.log("timer"), 0)

23-performance/232-promises-blocking-initial-withnextick.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//promise was resolved in the next tick..
44
//we are still blocking io.. (io executed last)
55
//if this was a listening socket no body can connect for a while
6+
console.time("IP")
7+
process.nextTick( () => console.timeEnd("IP"));
68
process.nextTick( ()=>console.log("TRUE END OF INITIAL PHASE--First next tick! "))
79
console.log("initial phase start...")
810
console.log ("Invoking promise then ")

23-performance/233-promises-initial-setimmediate.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2+
3+
14
//here we differed the execution of the promise
25
//to the check phase (offloading the initial phase and allowing loop to start)
36
//promise was resolved in the next tick after check..
@@ -6,6 +9,8 @@
69
//this is useful for sockets to establish connections /listening sockets early
710
//at least people can connect now !
811
//But the io callback got kicked later
12+
console.time("IP")
13+
process.nextTick( () => console.timeEnd("IP"));
914
process.nextTick( ()=>console.log("---TRUE END OF INITIAL PHASE--First next tick! "))
1015
console.log("initial phase start...")
1116
console.log ("Invoking promise then ")

23-performance/234-promises-initial-setimmediate-partitioning.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
//this is useful for sockets to establish connections /listening sockets early
66
//at least people can connect now !
77
//and we get the io whenver we get it as soon as possible
8-
8+
console.time("IP")
9+
process.nextTick( () => console.timeEnd("IP"));
910
process.nextTick( ()=>console.log("---TRUE END OF INITIAL PHASE--First next tick! "))
1011
console.log("initial phase start...")
1112
console.log ("Invoking promise then ")

23-performance/235-promises-initial-setimmediate-offloading-thread.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
//this is useful for sockets to establish connections /listening sockets early
66
//at least people can connect now !
77
//and we get the io whenver we get it as soon as possible
8-
8+
console.time("IP")
9+
process.nextTick( () => console.timeEnd("IP"));
910
const WorkerThreads = require('node:worker_threads');;
1011
//this tells us whether we are on the main thread or worker
1112
if (WorkerThreads.isMainThread) {

0 commit comments

Comments
 (0)