{"ScriptPreparationCode":null,"TestCases":[{"Name":"pubSub","Code":"class PubSub {\r\n constructor() {\r\n this.topics = new Map();\r\n }\r\n\r\n subscribe(topic, callback) {\r\n if (!this.topics.has(topic)) {\r\n this.topics.set(topic, new Set());\r\n }\r\n this.topics.get(topic).add(callback);\r\n }\r\n\r\n publish(topic, data) {\r\n if (!this.topics.has(topic)) {\r\n return;\r\n }\r\n this.topics.get(topic).forEach((callback) =\u003E {\r\n callback(data);\r\n });\r\n }\r\n\r\n\r\n unsubscribe(topic, callback) {\r\n if (!this.topics.has(topic)) {\r\n return;\r\n }\r\n this.topics.get(topic).delete(callback);\r\n }\r\n\r\n unsubscribeAll(topic) {\r\n if (!this.topics.has(topic)) {\r\n return;\r\n }\r\n this.topics.delete(topic);\r\n }\r\n}\r\n\r\nconst pubSub = new PubSub();\r\nlet i = 1001;\r\nconst results = [];\r\npubSub.subscribe(\u0027custom\u0027, (e) =\u003E {})\r\nwhile (--i) {\r\n pubSub.publish(\u0027custom\u0027, \u0027test\u0027)\r\n}","IsDeferred":false},{"Name":"custom event","Code":"let i = 1001;\r\nconst results = [];\r\n\r\nwhile (--i) {\r\n window.dispatchEvent(new CustomEvent(\u0027custom:test\u0027));\r\n}\r\n","IsDeferred":false}]}