Во-первых, реализуйте indexOf
в JavaScript для браузеров, которые уже не имеют его. Например, см. отдельно оплачиваемые предметы массива Erik Arvidsson (также, связанное сообщение в блоге ). И затем можно использовать indexOf
, не волнуясь о поддержке браузера. Вот немного оптимизированная версия его indexOf
реализация:
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (obj, fromIndex) {
if (fromIndex == null) {
fromIndex = 0;
} else if (fromIndex < 0) {
fromIndex = Math.max(0, this.length + fromIndex);
}
for (var i = fromIndex, j = this.length; i < j; i++) {
if (this[i] === obj)
return i;
}
return -1;
};
}
Это изменяется для хранения длины так, чтобы это не должно было смотреть он каждое повторение. Но различие не огромно. Функция менее общего назначения могла бы быть быстрее:
var include = Array.prototype.indexOf ?
function(arr, obj) { return arr.indexOf(obj) !== -1; } :
function(arr, obj) {
for(var i = -1, j = arr.length; ++i < j;)
if(arr[i] === obj) return true;
return false;
};
я предпочитаю использовать стандартную функцию и оставлять этот вид микрооптимизации для того, когда это действительно необходимо. Но если Вы увлечены микрооптимизацией, я адаптировался сравнительные тесты что roosterononacid, связанный с в комментариях, с сравнительный тест, ищущий в массивах . Они довольно сыры, хотя, полное расследование протестировало бы массивы с различными типами, различными длинами и находящими объектами, которые происходят в различных местах.
Да, использование может использовать tmux
или, более старое screen
. Следующее является выборками их соответствующего man
страницы:
tmux
:
tmux is a terminal multiplexer: it enables a number of terminals to be
created, accessed, and controlled from a single screen. tmux may be
detached from a screen and continue running in the background, then later
reattached.
When tmux is started it creates a new session with a single window and
displays it on screen. A status line at the bottom of the screen shows
information on the current session and is used to enter interactive
commands.
A session is a single collection of pseudo terminals under the management
of tmux. Each session has one or more windows linked to it. A window
occupies the entire screen and may be split into rectangular panes, each
of which is a separate pseudo terminal (the pty(4) manual page documents
the technical details of pseudo terminals). Any number of tmux instances
may connect to the same session, and any number of windows may be present
in the same session. Once all sessions are killed, tmux exits.
Each session is persistent and will survive accidental disconnection
(such as ssh(1) connection timeout) or intentional detaching (with the
'C-b d' key strokes). tmux may be reattached using:
$ tmux attach
screen
Screen is a full-screen window manager that multiplexes a physical
terminal between several processes (typically interactive shells).
Each virtual terminal provides the functions of a DEC VT100 terminal
and, in addition, several control functions from the ISO 6429 (ECMA 48,
ANSI X3.64) and ISO 2022 standards (e.g. insert/delete line and support
for multiple character sets). There is a scrollback history buffer for
each virtual terminal and a copy-and-paste mechanism that allows moving
text regions between windows.
When screen is called, it creates a single window with a shell in it
(or the specified command) and then gets out of your way so that you
can use the program as you normally would. Then, at any time, you can
create new (full-screen) windows with other programs in them (including
more shells), kill existing windows, view a list of windows, turn
output logging on and off, copy-and-paste text between windows, view
the scrollback history, switch between windows in whatever manner you
wish, etc. All windows run their programs completely independent of
each other. Programs continue to run when their window is currently not
visible and even when the whole screen session is detached from the
user's terminal. When a program terminates, screen (per default) kills
the window that contained it. If this window was in the foreground,
the display switches to the previous window; if none are left, screen
exits.
Обе из этих программ позволят Вам войти в систему сервера, запустить процесс, затем выйдут из системы и оставят его выполнением. Когда Вы хотите проверить его, Вы входите на сервере и снова соединяетесь с выполнением tmux
или screen
сессия, и это - как будто Вы никогда не уезжали. Можно установить их обоих из репозиториев Ubuntu:
sudo apt-get install screen
или
sudo apt-get install tmux
можно найти хороший Q& сравнение этих двух программ на нашем родственном сайте, Unix & Linux.