全局Timestamp管理器 检测js执行时间
随手写了个小工具,主要为了测试不同混淆程度的javascript脚本的加载速度
1. [代码]Timestamp.js
(function() {
if (typeof this.Timestamp == 'undefined') {
/**
* Global timestamp manager
* @author Janpoem
* created at 2011.03.30
*/
this.Timestamp = (function() {
var pool = {
'page_init': new Date()
};
return {
add: function(flag) {
pool[flag] = new Date();
},
get: function(flag) {
return typeof flag == 'undefined' ? pool : (pool[flag] ? pool[flag] : pool);
},
diff: function(to, diff) {
if (!diff)
diff = to, to = 'page_init';
return (pool[to] && pool[diff]) ? pool[diff] - pool[to] : 0;
}
}
}) ();
}
}) ();
2. [代码]实际用例
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MooTools Test Page</title>http://www.huiyi8.com/donghua/
<script type="text/javascript">flash
(function() {
// 由于为了测试单独加载某个脚本文件的实际速度,所以该对象的代码被直接加载写在页面中
if (typeof this.Timestamp == 'undefined') {
/**
* Global timestamp manager
* @author Janpoem
* created at 2011.03.30
*/
this.Timestamp = (function() {
var pool = {
'page_init': new Date()
};
return {
add: function(flag) {
pool[flag] = new Date();
},
get: function(flag) {
return typeof flag == 'undefined' ? pool : (pool[flag] ? pool[flag] : pool);
},
diff: function(to, diff) {
if (!diff)
diff = to, to = 'page_init';
return (pool[to] && pool[diff]) ? pool[diff] - pool[to] : 0;
}
}
}) ();
}
}) ();
</script>
<script type="text/javascript" src="all.js" onload="Timestamp.add('load_complate');"></script>
<script type="text/javascript">
Timestamp.add('process_here#1');
</script>
</head>
<body>
<div id="mt_test"></div>
<script type="text/javascript">
console.log(
Timestamp.diff('load_complate'), // download a script file speed
Timestamp.diff('process_here#1'), // html parse process here
Timestamp.diff('load_complate', 'process_here#1')
);
</script>
</body>
</html>
全局Timestamp管理器 检测js执行时间的更多相关文章
- 从零开始山寨Caffe·叁:全局线程管理器
你需要一个管家,随手召唤的那种,想吃啥就吃啥. ——设计一个全局线程管理器 一个机器学习系统,需要管理一些公共的配置信息,如何存储这些配置信息,是一个难题. 设计模式 MVC框架 在传统的MVC编程框 ...
- Node.js包管理器:
Node.js包管理器: 当我们要把某个包作为工程运行的一部分时,通过本地模式获取,如果要在命令行下使用,则使用全局模式安装 使用全局模式安装的包并不能直接在JavaScript文件中用require ...
- node.js 安装及配置(hello world)及 node 的包管理器(npm)
下载地址:Download | Node.js,无脑下一步安装即可: 安装时,会自动将 node 可执行文件路径添加进 Path 内,这样进入 cmd 命令行,以查看 node 的安装版本: > ...
- npm --- Node.js包管理器
目录 1. 安装Node.js 2. 运行npm 3. npm介绍 3.1 安装插件 3.2 更新插件 3.3 卸载插件 3.4 查看当前目录中的插件列表 4. 使用cnpm 4.1 安装 npm( ...
- 使用yarn代替npm作为node.js的模块管理器
使用yarn代替npm作为node.js的模块管理器 转 https://www.jianshu.com/p/bfe96f89da0e Fast, reliable, and secure d ...
- Node.js包管理器Yarn的入门介绍与安装
FAST, RELIABLE, AND SECURE DEPENDENCY MANAGEMENT. 就在昨天, Facebook 发布了新的 node.js 包管理器 Yarn 用以替代 npm .咱 ...
- JS模块规范 前端模块管理器
一:JS模块规范(为了将js文件像java类一样被import和使用而定义为模块, 组织js文件,实现良好的文件层次结构.调用结构) A:CommonJS就是为JS的表现来制定规范,因为js没有模块的 ...
- NET Core 静态文件及JS包管理器(npm, Bower)的使用
NET Core 静态文件及JS包管理器(npm, Bower)的使用 文章目录 在 ASP.NET Core 中添加静态文件 使用npm管理JavaScript包 使用Bower管理JavaScri ...
- [Web 前端] 使用yarn代替npm作为node.js的模块管理器
cp from : https://www.jianshu.com/p/bfe96f89da0e Fast, reliable, and secure dependency managemen ...
随机推荐
- BeautifulSoup实例
Beautiful Soup 4.4.0 中文文档:http://beautifulsoup.readthedocs.io/zh_CN/latest/ #coding:utf-8from bs4 im ...
- Dividing coins (01背包)
It’s commonly known that the Dutch have invented copper-wire. Two Dutch men were fighting over a nic ...
- CodeForces 632A
A - Grandma Laura and Apples Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- Kubernetes网络设计原则
在配置集群网络插件或者实践K8S 应用/服务部署请时刻想到这些原则: 1.每个Pod都拥有一个独立IP地址,Pod内所有容器共享一个网络命名空间 2.集群内所有Pod都在一个直接连通的扁平网络中,可通 ...
- noip 2010 数字统计
数位dp解水题 luogu1179 dp[i][j]表示 有i位,且首位是j(包括0) 的 ‘2’的个数 dp[i][j]={ Σ(dp[i-1][k]),j!=2; Σ(dp[i-1][k])+va ...
- POJ 2777 Count Color【线段树】
题目大意:要求完成以下两个操作:1.将一个区间刷上一种颜色2.询问一段区间上有多少种颜色 思路:这两个操作线段树都可以很迅速的完成,具体做法是:线段树上每个节点存这个线段上的颜色数量,由于颜色数很少, ...
- 《计算机网络课程设计》基本操作(基于Cisco Packet Tracer)
第一次课 Router> #用户模式 Router# #特权模式 lhx(config)# #全局配置模式 Router>enable #进入特权模式 Router#configure t ...
- 16 个常用的yum 命令
1. yum [-y] install package_name2. yum remove package_name 卸载指定软件3. ...
- python学习之-- IO多路复用 select模块
python I/O多路复用包括3个模块,上一篇已经说过概念,这里我使用的是select模块实现一个ftp并发 服务器端核心代码: import socket,select import queue, ...
- 为什么utf8占用3个字节
UNICODE是万能编码,包含了所有符号的编码,它规定了所有符号在计算机底层的二进制的表示顺序.有关Unicode为什么会出现就不叙述了,Unicode是针对所有计算机的使用者定义一套统一的编码规范, ...