- 浏览: 399793 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (309)
- xaml C# wpf (0)
- scala java inner clas (1)
- Tools UML Eclipse UML2 (1)
- Timer .NET Framework (1)
- perl (6)
- python function paramter (1)
- Python Docstring (1)
- Python how to compare types (1)
- Python (8)
- java (5)
- C# (76)
- C# WPF (0)
- p4 (0)
- WPF (46)
- .net (6)
- xaml (1)
- javascript (40)
- windows (10)
- scala (4)
- winform (1)
- c++ (48)
- tools (12)
- cmd (1)
- os (0)
- CI (0)
- shell (0)
- C (2)
- haskell (49)
- functional (1)
- tool (1)
- gnu (1)
- linux (1)
- kaskell (0)
- svn (0)
- wcf (3)
- android (1)
最新评论
javascript divide long operation into sub operations to improve responsiveness
- 博客分类:
- javascript
nowadays the browser is much more smarter and they normally possed some features that intelligently monitor the status of the web applications. If some process overruns, say, 5 seconds non-stop (browser suc as FireFox, and Opera does this, the Iphone actually kills any script that are running for more than 5 seconds without even opening a dialog.)
because of this ,it make sense to "reducing all complex operations (any more than a few hundred milliseconds)into manageable portions becomes a necessity.
below shows an example that will create 2000 rows, and each row is with 6 columns. this operation may take long to run as it create a log of DOM object.
var function1 = function () { // Normal, intensive, operation var table = document.getElementsByTagName("tbody")[0]; for (var i = 0; i < 2000; i++) { var tr = document.createElement("tr"); for (var t = 0; t < 6; t++) { var td = document.createElement("td"); td.appendChild(document.createTextNode("" + t)); tr.appendChild(td); } table.appendChild(tr); } }; window.onload = function1;
With the help of timer, you can reorganize the function as such (with all necessary html tags and others).
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <script type="text/javascript"> // this may be some expensive task, which when run in serialization, might cause the browser to be unresponsive. so it makes sense to divide the tasks into some subtasks. var function1 = function () { // Normal, intensive, operation var table = document.getElementsByTagName("tbody")[0]; for (var i = 0; i < 2000; i++) { var tr = document.createElement("tr"); for (var t = 0; t < 6; t++) { var td = document.createElement("td"); td.appendChild(document.createTextNode("" + t)); tr.appendChild(td); } table.appendChild(tr); } }; // while it is more natural(counter-natural when you are do the program) to split the long running operation so that each runs in piecemeal fragement so that the browser may become more responsive var fun2 = function () { var table = document.getElementsByTagName("tbody")[0]; var i = 0, max = 1999; setTimeout(function () { for (var step = i + 500; i < step; i++) { var tr = document.createElement("tr"); for (var t = 0; t < 6; t++) { var td = document.createElement("td"); td.appendChild(document.createTextNode("" + t)); tr.appendChild(td); } table.appendChild(tr); } if (i < max) { // the timeout value of 0 indicate that the function call will fire immediately setTimeout(arguments.callee, 0); } }, 0); }; window.onload = fun2; </script> <body> <!-- This example will demonstrate how we can make use of timer to split some expensive tasks into some non-expensive tasks. --> <table><tbody></tbody></table> </body> </html>
发表评论
-
javascript - trick to cross browser DOM ready event
2012-08-24 08:23 928the "ready" event ... -
javascript - trick to simulate mouseenter and mouseleave
2012-08-23 08:31 2254Previously we discussed javasc ... -
javascript - trick to simulate the change event
2012-08-22 08:51 1659In the previous discussion a ... -
javascript - trick to simulate bubbling submit event
2012-08-22 08:03 906In the previous discussion abou ... -
javascript - trick to implement bubbling submit event
2012-08-23 07:55 701Following up to the javascrip ... -
javascript - trick to detect bubbling supportability
2012-08-20 22:22 972Event delegation is oe of the b ... -
javascript - trigger event and custom events
2012-08-20 21:58 2078In the previous post - javascri ... -
javascript - trick to handlers management
2012-08-20 08:19 1024We have discussed "javascr ... -
javascript - trick to centralized store
2012-08-20 07:52 819For a number of reasons it's ... -
javascript - trick to fix the event object
2012-08-20 07:47 881Many browsers, especially In ... -
javascript - tricks to deal with colors
2012-08-15 08:34 766There are a couple of ways to r ... -
javascript - trick to manipulate the opacity
2012-08-15 08:26 766All other browsre may have supp ... -
javascript - trick to test visibility of an element
2012-08-15 08:15 522though there is a visible prope ... -
javascript - trick to get and set height and width
2012-08-15 08:05 549when looking at properties t ... -
javascript - trick to set/get attributes that expects px values
2012-08-16 11:00 517When setting a number into a ... -
javascript - trick to get and set CSS style
2012-08-16 11:00 747while it will not be so much tr ... -
javascript - trick to normalize href for IE
2012-08-16 10:59 533IE is again the only browser th ... -
javascript - trick IE form and its expando attribute
2012-08-16 10:59 1042there is a known issue that if ... -
javascript expando and attributes
2012-08-14 08:15 1039expando is something like this ... -
javascript - trick to getText and setText
2012-08-14 07:40 1144it is not as simple as you thin ...
相关推荐
Then we will be looking into algorithm analysis, we will be looking into brute force algorithms, greedy algorithms, divide and conquer algorithms, dynamic programming, reduction, and backtracking. ...
在"JUnit测试Sum_Divide"这个项目中,我们可以理解为作者创建了一个用于测试整数除法操作的测试类或方法。下面我们将深入探讨JUnit的基本概念、如何创建测试用例以及如何进行整数除法的测试。 首先,JUnit是一个...
本压缩包中的"divide"文件很可能是Verilog编写的分频器代码,它在数字系统中有着广泛的应用,例如时钟管理、计数器、信号处理等场景。 分频是数字信号处理中的基本操作,它的原理是将输入的时钟信号频率降低到一个...
它不仅用于存储图像,还可以执行各种数学运算,包括加法(`add`)和除法(`divide`)。这两个运算在计算机视觉和图像处理中至关重要,因为它们常用于图像增强、滤波以及特征检测等任务。 ### `Mat`类简述 `Mat`类是...
The chapter may cover techniques such as long division or binary division methods to divide one binary number by another. **Floating-Point Numbers and Operations** Floating-point numbers are used ...
This is a convenient feature when you're manually comparing files, when you want to copy/paste between multiple files, or when you simply want to divide up your edit space. Tabbed Child Windows ...
根据给定文件的信息,我们可以详细探讨lpm_divide Megafunction用户使用手册中的关键知识点。此手册提供了关于在FPGA设计中使用Altera(现在的Intel Programmable Solutions Group)提供的lpm_divide Megafunction的...
JavaScript计算器是一种基于Web的交互式计算工具,它利用JavaScript编程语言实现,可以在用户的浏览器上运行,无需服务器支持。JavaScript计算器可以执行基本的数学运算,如加、减、乘、除,甚至可以处理更复杂的...
2. **算术操作**:提供加法(`add`)、减法(`subtract`)、乘法(`multiply`)、除法(`divide`)等基本算术运算,这些操作能确保结果的精度不受JavaScript Number类型的限制。 3. **比较操作**:支持小于(`lt`)...
JavaScript提供了内置的数学函数,如`Math.add()`, `Math.subtract()`, `Math.multiply()`, 和 `Math.divide()`,可以用来执行基本的加减乘除运算。对于更复杂的计算,如求平方根或指数,也可以使用`Math.sqrt()`和`...
标题"CLK_DIVIDE_look_veriloghdl_clockdivider_"暗示我们将探讨一种使用Verilog HDL(硬件描述语言)实现的时钟分频器,特别是采用了“Carry Look Ahead”技术的时钟分频器。描述中的"CARRY LOOK AHEAD USING ...
在本文中,我们将深入探讨如何使用JavaScript来实现一个基本的网页计算器。JavaScript是一种广泛用于创建交互式网页的脚本语言,它可以与HTML和CSS紧密结合,为用户带来动态体验。在这个项目中,我们专注于构建一个...
在本文中,我们将深入探讨“clk_divide.rar_clk_divide”这个项目,它提供了一种通用的分频器实现,能够满足各种分频需求。 首先,我们要理解什么是时钟分频。时钟是数字系统中的心跳,控制着所有的操作和数据传输...
examples to simplify problems, and divide-and-conquer strategies to break complex problems into manageable pieces. The topic of Chapter 7 is performance optimization. If there are multiple solutions ...
"divide_除法器实现_" 可能指的是一个简单的除法器设计,它能一次性提供一个或两个商的值。这种设计可能采用分步迭代的方法,其中每个时钟周期处理一部分除法操作。例如,它可能包含以下步骤: 1. **初始化**:设置...
标题中的"divide_valarray_value.rar_The Divide"可能是指一个软件或库的特定部分,它涉及到数值计算,特别是与除法操作相关的功能。在C++编程中,`valarray`是一个标准库容器,用于处理数组值,特别是进行高效且...
划分divIDE是一个javascript面板管理库。 许多GUI应用程序都有多个面板/窗格/窗口,其中显示了图形/按钮/工具栏。 divIDE允许将窗口中的这些分区创建为托管对象。 这样,每个面板都可以是一种类型,例如文本区域,...
### JavaScript语言教程及案例知识点详解 #### 一、JavaScript简介 **JavaScript** 是一种广泛使用的高级编程语言,它被设计成一种轻量级的语言,并且主要用于网页开发中为静态页面添加交互性和动态功能。...