VIM + JSON: загрузка файла в переменную

и другие vi-подобные редакторы

Модератор: /dev/random

Ответить
Аватара пользователя
ZyX
Сообщения: 355
ОС: Gentoo

VIM + JSON: загрузка файла в переменную

Сообщение ZyX »

У меня вопрос: это нормальный способ сохранения и, главное, загрузки переменной
из файла или нет? Нужно, чтобы значение можно было без особого геморроя читать
и редактировать не только Vim’ом, для чего был выбран JSON:

Код: Выделить всё

"{{{1 JSON
"{{{2 Загрузка переменной из JSON-файла
function LoadJSONtoVar(varname, filename)
    let null=''
    let true=1
    let false=0
    let l:loader="import vim\n".
                \"try:\n".
                \"    import simplejson as json\n".
                \"    filename='".escape(a:filename, "\\'")."'\n".
                \"    fd=open(filename, \"r\")\n".
                \"    jobj=json.load(fd)\n".
                \"    fd.close()\n".
                \"    vim.command(\"let ".a:varname."=\"+json.dumps(jobj))".
                \"except:\n".
                \"    raise"
    execute "python ".l:loader
    return 1
endfunction
"{{{2 Выгрузка переменной в JSON-файл
function DumpVarToJSON(varname, filename)
    let l:dumper="import vim\n".
                \"try:\n".
                \"    import simplejson as json\n".
                \"    variable=vim.eval('".escape(a:varname, "\\'")."')\n".
                \"    filename='".escape(a:filename, "\\'")."'\n".
                \"    fd=open(filename, \"w\")\n".
                \"    json.dump(variable, fd)\n".
                \"    fd.close()\n".
                \"except:\n".
                \"    raise"
    execute "python ".l:dumper
endfunction
Спасибо сказали:
Аватара пользователя
ZyX
Сообщения: 355
ОС: Gentoo

Re: VIM + JSON: загрузка файла в переменную

Сообщение ZyX »

Написал загрузчик/выгрузчик JSON на vimscript. Работает как минимум в 10 раз
медленнее чем vim+python+simplejson. Здесь версия, которая может использовать
и мои функции, и Python:

Код:

let s:F={"json":{},"main":} "{{{2 Глобальная переменная let s:g={} "{{{3 Сообщения об ошибка let s:g.errstr={ \"type": { \ "file": "BadFile", \ "syntax": "SyntaxErr", \}, \"value": { \ "r": "File not readable", \ "w": "File not writable", \ "rjson": "Failed to read JSON file", \ "jstr": "Invalid JSON string", \ "jse": "JSON string must end with “\"”", \ "jsu": "“\u” must be followed by four hex digits", \ "jsie": "Invalid escape: backslash must be followed by ". \ "“u” and four hex digits or ". \ "one of the following characters: ". \ "“\”, “/”, “b”, “f”, “n”, “r”, “t”", \ "jobj": "Invalid JSON object", \ "jkey": "Key in JSON object must be of a type “string”", \ "jdup": "Duplicate key", \ "jdt": "“:” not found", \ "jcoma": "Missing comma", \ "joe": "Object must end with “}”", \ "jlist": "Invalid JSON list", \ "jle": "List must end with “]”", \}, \} "{{{3 Значения для JSON let s:g.json={ \"values": { \ "null": "", \ "true": 1, \ "false": 0, \}, \"escapes": { \ '"': '"', \ '\': '\', \ '/': '/', \ 'b': "\b", \ 'f': "\f", \ 'n': "\n", \ 'r': "\r", \ 't': "\t", \}, \"lstinner": { \ "result": [], \ "delta": 1, \ "endch": ']', \ "errargs": ["json.getlst", "syntax", s:g.errstr.value.jlist, \ s:g.errstr.value.jle], \}, \"objinner": { \ "result": {}, \ "delta": 1, \ "endch": '}', \ "errargs": ["json.getobj", "syntax", s:g.errstr.value.jobj, \ s:g.errstr.value.joe], \}, \"escrev": {}, \ "acts": {}, \ "dacts": {}, \ "ws": [' ', "\t", "\n", "\r",], \} call map(map(copy(s:g.json.escapes), '{v:val : "\\".v:key}'), \'extend(s:g.json.escrev, v:val)') let s:g.json.valregex=join(keys(s:g.json.values), '\|') let s:g.json.numregex='^-\=\([1-9]\d*\|0\)\(\.\d\+\)\=\([eE][+\-]\=\d\+\)\=' let s:g.json.strregex='^"\([^\\"]\|\\\(u\x\{4}\|'. \'['.escape(join(keys(s:g.json.escapes), ''), '\[]-').']\)\)*"' "{{{2 stuf "{{{3 stuf.checkwr " Проверка, можно ли писать в файл function s:F.stuf.checkwr(fname) return (filewritable(a:fname)==1 || \filewritable(fnamemodify(a:fname, ":p:h"))==2) endfunction "{{{2 json "{{{3 JSON dumper/vimscript "{{{4 json.strstr function s:F.json.strstr(string) if !len(a:string) return "null" endif let result='"' let idx=0 let slen=len(a:string) while idx<slen let charnr=char2nr(a:string[(idx):]) let char=nr2char(charnr) let clen=len(char) let idx+=clen if clen>1 let result.=substitute(printf("%0.4x", charnr), \'.\{4}', '\\u\0', 'g') elseif has_key(s:g.json.escrev, char) let result.=s:g.json.escrev[char] else let result.=char endif endwhile return result.'"' endfunction "{{{4 json.strlst function s:F.json.strlst(list) return '['.join(map(copy(a:list), 's:F.json.str(v:val)'), ',').']' endfunction "{{{4 json.strdct function s:F.json.strdct(dict) return '{'.join(values(map(copy(a:dict), \'s:F.json.strstr(v:key).":".s:F.json.str(v:val)')), \',').'}' endfunction "{{{4 json.strfunc function s:F.json.strfunc(f) return "null" endfunction "{{{4 json.str function s:F.json.str(obj) return call(s:g.json.dacts[type(a:obj)], [a:obj], {}) endfunction "{{{4 json.dumps function s:F.json.dumps(obj) return s:F.json.str(a:obj) endfunction "{{{4 s:g let s:g.json.dacts=[function("string"), s:F.json.strstr, \s:F.json.strfunc, s:F.json.strlst, s:F.json.strdct, \function("string")] lockvar! s:g.json.dacts "{{{3 Парсер JSON на vimscript " Примерно в двадцать раз медленнее Python "{{{4 json.getnum function s:F.json.getnum(text) let numstr=matchstr(a:text, s:g.json.numregex) if numstr=~?'e' " 0e0 → 0.0e0 let numstr=substitute(numstr, '^-\=\d\+[eE]\@=', '\0.0', '') endif return { "delta": len(numstr), \"result": eval(numstr),} endfunction "{{{4 json.getstr function s:F.json.getstr(text) let selfname='json.getstr' let str=matchstr(a:text, s:g.json.strregex) let delta=len(str) if !delta return s:F.main.eerror(selfname, 'syntax', \s:g.errstr.value.jstr) endif return { "delta": delta, \"result": eval(str),} endfunction "{{{4 json.getobj function s:F.json.getobj(text) let selfname="json.getobj" let tlen=len(a:text) let inner=deepcopy(s:g.json.objinner) let inner.text=a:text while inner.delta<tlen let keystart=match(a:text, '^\_\s*\zs"', inner.delta) if keystart==-1 return s:F.json.end(inner) endif let inner.delta=keystart let lastret=s:F.json.getstr(a:text[(inner.delta):]) if type(lastret)==type(0) return s:F.main.eerror(selfname, 'syntax', \s:g.errstr.value.jobj, \s:g.errstr.value.jkey) endif let inner.delta+=lastret.delta let key=lastret.result unlet lastret if has_key(inner.result, key) return s:F.main.eerror(selfname, 'syntax', \s:g.errstr.value.jobj, \s:g.errstr.value.jdup) endif let resstart=match(a:text, '^\_\s*\zs:', inner.delta) if resstart==-1 return s:F.main.eerror(selfname, 'syntax', \s:g.errstr.value.jobj, \s:g.errstr.value.jdt) endif let inner.delta=resstart+1 let lastret=s:F.json.get(a:text[(inner.delta):]) if type(lastret)==type(0) return lastret endif let inner.delta+=lastret.delta let inner.result[key]=lastret.result unlet lastret let comma=match(a:text, '^\_\s*\zs,', inner.delta) if (comma)==-1 return s:F.json.end(inner) endif let inner.delta=(comma+1) endwhile return s:F.main.eerror(selfname, 'syntax', \s:g.errstr.value.jobj, \s:g.errstr.value.joe) endfunction "{{{4 json.getlst function s:F.json.getlst(text) let selfname="json.getlst" let tlen=len(a:text) let inner=deepcopy(s:g.json.lstinner) let inner.text=a:text while inner.delta<tlen let lastret=s:F.json.get(a:text[(inner.delta):]) if type(lastret)==type(0) return s:F.json.end(inner) endif let inner.delta+=lastret.delta call add(inner.result, lastret.result) unlet lastret let comma=match(a:text, '^\_\s*\zs,', inner.delta) if (comma)==-1 return s:F.json.end(inner) endif let inner.delta=(comma+1) endwhile return s:F.main.eerror(selfname, 'syntax', \s:g.errstr.value.jlist, \s:g.errstr.value.jle) endfunction "{{{4 json.get function s:F.json.get(text) let selfname="json.get" let delta=match(a:text, '\_\s*\zs[\[{"tfn[:digit:].\-]') if delta==-1 return 0 endif let char=a:text[(delta)] if has_key(s:g.json.acts, char) let lastret=call(s:g.json.acts[char], [a:text[(delta):]], {}) if type(lastret)==type({}) let lastret.delta+=delta endif return lastret elseif char=~#'[[:digit:].\-]' let lastret=s:F.json.getnum(a:text[(delta):]) if type(lastret)==type({}) let lastret.delta+=delta endif return lastret else let str=matchstr(a:text, s:g.json.valregex, delta) let lstr=len(str) if !lstr return 0 endif return { "delta": delta+lstr, \"result": s:g.json.values[str], } endif endfunction "{{{4 json.end function s:F.json.end(inner) let end=match(a:inner.text, '^\_\s*\zs'.a:inner.endch, a:inner.delta) if (end)!=-1 return { "delta": (end+1), \"result": a:inner.result,} endif return call(s:F.main.eerror, a:inner.errargs, {}) endfunction "{{{4 json.loads function s:F.json.loads(text) let selfname="json.loads" let lastret=s:F.json.get(a:text) if type(lastret)==type(0) call s:F.main.eerror(selfname, "file", s:g.errstr.value.rjson) throw "FileNotReadable" endif return lastret.result endfunction "{{{4 s:g let s:g.json.acts={ \'"': s:F.json.getstr, \'[': s:F.json.getlst, \'{': s:F.json.getobj, \} lockvar! s:g.json.acts "{{{3 json.load " Загрузка переменной из JSON-файла function s:F.json.load(fname) let selfname="json.load" if !filereadable(a:fname) call s:F.main.eerror(selfname, "file", s:g.errstr.value.r) throw "FileNotReadable" endif if !has("python") || !s:F.main.option("UsePython") return s:F.json.loads(join(readfile(a:fname), "\n")) endif let null='' let true=1 let false=0 python import vim try python import simplejson as json catch return s:F.json.loads(join(readfile(a:fname), "\n")) endtry python fd=open(vim.eval("a:fname"), "r") try python jobj=json.load(fd) catch call s:F.main.eerror(selfname, "file", s:g.errstr.value.rjson) throw "FileNotReadable" endtry python fd.close() python vim.command("let tmp="+json.dumps(jobj)) return tmp endfunction "{{{3 json.dump " Выгрузка переменной в JSON-файл function s:F.json.dump(fname, what) let selfname="json.dump" if !s:F.stuf.checkwr(a:fname) return s:F.main.eerror(selfname, "file", s:g.errstr.value.w) endif if !has("python") || !s:F.main.option("UsePython") return writefile([s:F.json.dumps(a:what)], a:fname)!=-1 endif python import vim try python import simplejson as json catch return writefile([s:F.json.dumps(a:what)], a:fname)!=-1 endtry python variable=vim.eval("a:what") python fd=open(vim.eval("a:fname"), "w") python json.dump(variable, fd) python fd.close() return 1 endfunction "{{{2 main "{{{3 main.eerror " Вывести ошибку function s:F.main.eerror(from, type, ...) let comm=((len(a:000))? \("(".(join(map(copy(a:000), \ '(type(v:val)==type(""))? v:val : string(v:val)'), \ ': ')).")"): \("")) echohl Error echo "tr3/".a:from.":".(s:g.errstr.type[(a:type)]).(comm) echohl None return 0 endfunction "{{{3 mait.option function s:F.main.option(option) if a:option==#"UsePython" return 1 endif endfunction
Спасибо сказали:
Аватара пользователя
ZyX
Сообщения: 355
ОС: Gentoo

Re: VIM + JSON: загрузка файла в переменную

Сообщение ZyX »

Проверка производительности различных способов чтения файла:

Код: Выделить всё

let g:max=10
let g:fname="/home/zyx/.vim/plugin/translit3.vim"
python import vim
python import simplejson
python import demjson
function Python2()
    let i=0
    while i < g:max
        python fd=open(vim.eval("g:fname"), "r")
        python vim.command("let tmp="+simplejson.dumps(fd.read()))
        python fd.close()
        unlet tmp
        let i+=1
    endwhile
endfunction
function Vim1()
    let i=0
    while i < g:max
        let tmp=join(readfile(g:fname, "b"), "\n")
        unlet tmp
        let i+=1
    endwhile
endfunction
function Vim2()
    let i=0
    while i < g:max
        execute "view! ".g:fname
        let tmp=join(getline(0, '$'), "\n")
        unlet tmp
        bw
        let i+=1
    endwhile
endfunction
function Vim3()
    let i=0
    while i < g:max
        execute "view! ".g:fname
        let savedreg=@a
        normal! gg"ayG
        let tmp=@a
        unlet tmp
        let @a=savedreg
        bw
        let i+=1
    endwhile
endfunction
function Vim4()
    let i=0
    while i < g:max
        execute "enew!"
        execute "read ".g:fname
        let savedreg=@a
        normal! gg"aG
        let tmp=@a
        unlet tmp
        let @a=savedreg
        bw!
        let i+=1
    endwhile
endfunction
function System1()
    let i=0
    while i<g:max
        let tmp=system("cat ".shellescape(g:fname))
        unlet tmp
        let i+=1
    endwhile
endfunction
profile start lprofile
profile func *
echo "python2"
call Python2()
echo "vim1"
call Vim1()
echo "vim2"
call Vim2()
echo "vim3"
call Vim3()
echo "vim4"
call Vim4()
echo "system1"
call System1()
qa!

Как думаете, что окажется в файле lprofile (то есть, что будет быстрее)?
Спасибо сказали:
Аватара пользователя
Luinnar
Сообщения: 246
ОС: Solaris, Debian, Ubuntu

Re: VIM + JSON: загрузка файла в переменную

Сообщение Luinnar »

ZyX писал(а):
22.02.2010 16:52
Проверка производительности различных способов чтения файла:
...
Как думаете, что окажется в файле lprofile (то есть, что будет быстрее)?

Зачем спрашиваете? Лучше сразу выкладывайте! ;)
Спасибо сказали:
Аватара пользователя
ZyX
Сообщения: 355
ОС: Gentoo

Re: VIM + JSON: загрузка файла в переменную

Сообщение ZyX »

Ну, может у кого не так. Просто удивительно, что вызов system оказался намного
быстрее стандартного readfile (причём readfile без "b", вызов Python также
быстрее, хотя мы и перегоняем весь файл в JSON). К system вплотную приблизился
извращённый Vim4 (создание нового буфера, read в нём, копирование в буфер
и копирование буфера в переменную. Опасен, так как неизвестно, что там навесили
на автокоманды). Вот результаты для vim -c source\ test.vim:

Код: Выделить всё

FUNCTION  <SNR>38_MapDelimiters()
Called 800 times
Total time:   0.070617
 Self time:   0.018863

count  total (s)   self (s)
  800   0.068176   0.016422     call s:MapDelimitersWithAlternative(a:left, a:right, "", "")

FUNCTION  <SNR>38_MapDelimitersWithAlternative()
Called 800 times
Total time:   0.051754
 Self time:   0.051754

count  total (s)   self (s)
  800              0.012902     if !exists('g:NERD_' . &filetype . '_alt_style')
  800              0.006012         let b:left = a:left
  800              0.004388         let b:right = a:right
  800              0.004504         let b:leftAlt = a:leftAlt
  800              0.004391         let b:rightAlt = a:rightAlt
  800              0.001847     else
                                    let b:left = a:leftAlt
                                    let b:right = a:rightAlt
                                    let b:leftAlt = a:left
                                    let b:rightAlt = a:right
                                endif

FUNCTION  <SNR>52_IsInList()
Called 800 times
Total time:   0.190413
 Self time:   0.190413

count  total (s)   self (s)
12600              0.045888     for l:item in a:list
12400              0.050585         if a:i == l:item
  600              0.001540             return 1
                                    endif
11800              0.022318     endfor
  200              0.000576     return 0

FUNCTION  <SNR>52_DoModelines()
Called 200 times
Total time:   9.294414
 Self time:   0.093159

count  total (s)   self (s)
  200              0.001983     if line("$") > g:secure_modelines_modelines
  200              0.001744         let l:lines={ }
  200              0.029251         call map(filter(getline(1, g:secure_modelines_modelines) + getline(line("$") - g:secure_modelines_modelines, "$"), 'v:val =~ ":"'), 'extend(l:lines, { v:val : 0 } )')
 1400              0.009494         for l:line in keys(l:lines)
 1200   9.224248   0.022993             call <SID>DoModeline(l:line)
 1200              0.006905         endfor
  200              0.000421     else
                                    for l:line in getline(1, "$")
                                        call <SID>DoModeline(l:line)
                                    endfor
                                endif

FUNCTION  <SNR>61_LocalBrowse()
Called 600 times
Total time:   0.036820
 Self time:   0.036820

count  total (s)   self (s)
                              " unfortunate interaction -- debugging calls can't be used here;
                              " the BufEnter event causes triggering when attempts to write to
                              " the DBG buffer are made.
                            "  echomsg "dirname<".a:dirname.">"
  600              0.006313   if has("amiga")
                               " The check against '' is made for the Amiga, where the empty
                               " string is the current directory and not checking would break
                               " things such as the help command.
                               if a:dirname != '' && isdirectory(a:dirname)
                                silent! call netrw#LocalBrowseCheck(a:dirname)
                               endif
                              elseif isdirectory(a:dirname)
                            "   echomsg "dirname<".dirname."> isdir"
                               silent! call netrw#LocalBrowseCheck(a:dirname)
                              endif
                              " not a directory, ignore it

FUNCTION  <SNR>26_LoadFTPlugin()
Called 400 times
Total time:   1.016453
 Self time:   0.337998

count  total (s)   self (s)
  400              0.006804     if exists("b:undo_ftplugin")
  200              0.009326       exe b:undo_ftplugin
  200              0.001270       unlet! b:undo_ftplugin b:did_ftplugin
  200              0.000393     endif

  400              0.005800     let s = expand("<amatch>")
  400              0.002177     if s != ""
  400              0.012124       if &cpo =~# "S" && exists("b:did_ftplugin")
                                " In compatible mode options are reset to the global values, need to
                                " set the local values also when a plugin was already used.
                                unlet b:did_ftplugin
                                  endif

                                  " When there is a dot it is used to separate filetype names.  Thus for
                                  " "aaa.bbb" load "aaa" and then "bbb".
  800              0.008637       for name in split(s, '\.')
  400   0.946211   0.267756     exe 'runtime! ftplugin/' . name . '.vim ftplugin/' . name . '_*.vim ftplugin/' . name . '/*.vim'
  400              0.003155       endfor
  400              0.001730     endif

FUNCTION  Python2()
Called 1 time
Total time:   2.000531
 Self time:   2.000531

count  total (s)   self (s)
    1              0.000011     let i=0
  101              0.000722     while i < g:max
  100              0.015554         python fd=open(vim.eval("g:fname"), "rb")
  100              1.960365         python vim.command("let tmp="+simplejson.dumps(fd.read()))
  100              0.016093         python fd.close()
  100              0.005075         unlet tmp
  100              0.001512         let i+=1
  100              0.000528     endwhile

FUNCTION  <SNR>52_DoOne()
Called 800 times
Total time:   8.908116
 Self time:   0.094078

count  total (s)   self (s)
  800              0.032740     let l:matches = matchlist(a:item, '^\([a-z]\+\)\%(=[a-zA-Z0-9_\-.]\+\)\?$')
  800              0.007042     if len(l:matches) > 0
  800   0.205266   0.014853         if <SID>IsInList(g:secure_modelines_allowed_items, l:matches[1])
  600   8.642525   0.018900             exec "setlocal " . a:item
  600              0.002882         elseif g:secure_modelines_verbose
                                        echohl WarningMsg
                                        echomsg "Ignoring '" . a:item . "' in modeline"
                                        echohl None
                                    endif
  800              0.001266     endif

FUNCTION  <SNR>3_SynSet()
Called 400 times
Total time:  14.306784
 Self time:   0.374119

count  total (s)   self (s)
                              " clear syntax for :set syntax=OFF  and any syntax name that doesn't exist
  400              0.192228   syn clear
  400              0.005175   if exists("b:current_syntax")
                                unlet b:current_syntax
                              endif

  400              0.004444   let s = expand("<amatch>")
  400              0.002157   if s == "ON"
                                " :set syntax=ON
                                if &filetype == ""
                                  echohl ErrorMsg
                                  echo "filetype unknown"
                                  echohl None
                                endif
                                let s = &filetype
                              endif

  400              0.001644   if s != ""
                                " Load the syntax file(s).  When there are several, separated by dots,
                                " load each in sequence.
  800              0.010997     for name in split(s, '\.')
  400  14.064387   0.131722       exe "runtime! syntax/" . name . ".vim syntax/" . name . "/*.vim"
  400              0.002039     endfor
  400              0.000909   endif

FUNCTION  <SNR>52_DoNoSetModeline()
Called 200 times
Total time:   8.943923
 Self time:   0.035807

count  total (s)   self (s)
 1000              0.009629     for l:item in split(a:line, '[ \t:]')
  800   8.925437   0.017321         call <SID>DoOne(l:item)
  800              0.003487     endfor

FUNCTION  Vim2()
Called 1 time
Total time:  17.870079
 Self time:   8.309971

count  total (s)   self (s)
    1              0.000006     let i=0
  101              0.000568     while i < g:max
  100   9.820298   0.571968         execute "view! ".g:fname
  100              7.538288         let tmp=join(getline(0, '$'), "\n")
  100              0.026637         unlet tmp
  100   0.481986   0.170208         bw
  100              0.001146         let i+=1
  100              0.000352     endwhile

FUNCTION  <SNR>28_LoadIndent()
Called 400 times
Total time:   0.134854
 Self time:   0.102725

count  total (s)   self (s)
  400              0.004191     if exists("b:undo_indent")
                                  exe b:undo_indent
                                  unlet! b:undo_indent b:did_indent
                                endif
  400              0.005306     let s = expand("<amatch>")
  400              0.002186     if s != ""
  400              0.003028       if exists("b:did_indent")
  200              0.001052     unlet b:did_indent
  200              0.000365       endif

                                  " When there is a dot it is used to separate filetype names.  Thus for
                                  " "aaa.bbb" load "indent/aaa.vim" and then "indent/bbb.vim".
  800              0.008028       for name in split(s, '\.')
  400   0.094680   0.062551     exe 'runtime! indent/' . name . '.vim'
  400              0.001254       endfor
  400              0.000819     endif

FUNCTION  <SNR>38_SetUpForNewFiletype()
Called 1200 times
Total time:   2.686825
 Self time:   2.616208

count  total (s)   self (s)
                                "if we have already set the delimiters for this buffer then dont go thru
                                "it again
 1200              0.015536     if !a:forceReset && exists("b:left") && b:left != ''
  400              0.001325         return
                                endif

  800              0.005814     let b:sexyComMarker = ''

                                "check the filetype against all known filetypes to see if we have
                                "hardcoded the comment delimiters to use
  800              0.004507     if a:filetype == ""
  400   0.039722   0.006200         call s:MapDelimiters('', '')
  400              0.001597     elseif a:filetype == "aap"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "abaqus"
                                    call s:MapDelimiters('**', '')
                                elseif a:filetype == "abc"
                                    call s:MapDelimiters('%', '')
                                elseif a:filetype == "acedb"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "ada"
                                    call s:MapDelimitersWithAlternative('--','', '--  ', '')
                                elseif a:filetype == "ahdl"
                                    call s:MapDelimiters('--', '')
                                elseif a:filetype == "ahk"
                                    call s:MapDelimitersWithAlternative(';', '', '/*', '*/')
                                elseif a:filetype == "amiga"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "aml"
                                    call s:MapDelimiters('/*', '')
                                elseif a:filetype == "ampl"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "ant"
                                    call s:MapDelimiters('<!--','-->')
                                elseif a:filetype == "apache"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "apachestyle"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "asm68k"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "asm"
                                    call s:MapDelimitersWithAlternative(';', '', '#', '')
                                elseif a:filetype == "asn"
                                    call s:MapDelimiters('--', '')
                                elseif a:filetype == "aspvbs"
                                    call s:MapDelimiters('''', '')
                                elseif a:filetype == "asterisk"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "asy"
                                    call s:MapDelimiters('//', '')
                                elseif a:filetype == "atlas"
                                    call s:MapDelimiters('C','$')
                                elseif a:filetype == "autohotkey"
                                    call s:MapDelimiters(';','')
                                elseif a:filetype == "autoit"
                                    call s:MapDelimiters(';','')
                                elseif a:filetype == "automake"
                                    call s:MapDelimitersWithAlternative('#','', 'dnl ', '')
                                elseif a:filetype == "ave"
                                    call s:MapDelimiters("'",'')
                                elseif a:filetype == "awk"
                                    call s:MapDelimiters('#','')
                                elseif a:filetype == "basic"
                                    call s:MapDelimitersWithAlternative("'",'', 'REM ', '')
                                elseif a:filetype == "b"
                                    call s:MapDelimiters('/*','*/')
                                elseif a:filetype == "bbx"
                                    call s:MapDelimiters('%', '')
                                elseif a:filetype == "bc"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "bdf"
                                    call s:MapDelimiters('COMMENT ', '')
                                elseif a:filetype == "bib"
                                    call s:MapDelimiters('%','')
                                elseif a:filetype == "bindzone"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "bst"
                                    call s:MapDelimiters('%', '')
                                elseif a:filetype == "btm"
                                    call s:MapDelimiters('::', '')
                                elseif a:filetype == "bzr"
                                    call s:MapDelimiters('', '')
                                elseif a:filetype == "caos"
                                    call s:MapDelimiters('*', '')
                                elseif a:filetype == "catalog"
                                    call s:MapDelimiters('--','--')
                                elseif a:filetype == "c"
                                    call s:MapDelimitersWithAlternative('/*','*/', '//', '')
                                elseif a:filetype == "cfg"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "cg"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "ch"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "changelog"
                                    call s:MapDelimiters('','')
                                elseif a:filetype == "cl"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "clean"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "clipper"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "cmake"
                                    call s:MapDelimiters('#','')
                                elseif a:filetype == "cobol"
                                    call s:MapDelimiters('', '')
                                elseif a:filetype == "conf"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "config"
                                    call s:MapDelimiters('dnl ', '')
                                elseif a:filetype == "context"
                                    call s:MapDelimiters('%','')
                                elseif a:filetype == "cpp"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "crontab"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "cs"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "csc"
                                    call s:MapDelimiters('/*','*/')
                                elseif a:filetype == "csp"
                                    call s:MapDelimiters('--', '')
                                elseif a:filetype == "css"
                                    call s:MapDelimiters('/*','*/')
                                elseif a:filetype == "cterm"
                                    call s:MapDelimiters('*', '')
                                elseif a:filetype == "cupl"
                                    call s:MapDelimiters('/*','*/')
                                elseif a:filetype == "csv"
                                    call s:MapDelimiters('','')
                                elseif a:filetype == "cvs"
                                    call s:MapDelimiters('CVS:','')
                                elseif a:filetype == "CVSAnnotate"
                                    call s:MapDelimiters('','')
                                elseif a:filetype == "d"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "dcl"
                                    call s:MapDelimiters('$!', '')
                                elseif a:filetype == "dakota"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "debchangelog"
                                    call s:MapDelimiters('', '')
                                elseif a:filetype == "debcontrol"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "debsources"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "def"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "desktop"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "diff"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "django"
                                    call s:MapDelimitersWithAlternative('<!--','-->', '{#', '#}')
                                elseif a:filetype == "docbk"
                                    call s:MapDelimiters('<!--', '-->')
                                elseif a:filetype == "dns"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "dosbatch"
                                    call s:MapDelimitersWithAlternative('REM ','', '::', '')
                                elseif a:filetype == "dosini"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "dot"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "dracula"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "dsl"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "dtd"
                                    call s:MapDelimiters('<!--','-->')
                                elseif a:filetype == "dtml"
                                    call s:MapDelimiters('<dtml-comment>','</dtml-comment>')
                                elseif a:filetype == "dtrace"
                                    call s:MapDelimiters('/*','*/')
                                elseif a:filetype == "dylan"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == 'ebuild'
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "ecd"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == 'eclass'
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "eiffel"
                                    call s:MapDelimiters('--', '')
                                elseif a:filetype == "elf"
                                    call s:MapDelimiters("'", '')
                                elseif a:filetype == "elmfilt"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "erlang"
                                    call s:MapDelimiters('%', '')
                                elseif a:filetype == "eruby"
                                    call s:MapDelimitersWithAlternative('<!--', '-->', '<%#', '%>')
                                elseif a:filetype == "eterm"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "expect"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "exports"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "factor"
                                    call s:MapDelimitersWithAlternative('! ', '', '!# ', '')
                                elseif a:filetype == "fetchmail"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "fgl"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "focexec"
                                    call s:MapDelimiters('-*', '')
                                elseif a:filetype == "form"
                                    call s:MapDelimiters('*', '')
                                elseif a:filetype == "fortran"
                                    call s:MapDelimiters('!', '')
                                elseif a:filetype == "foxpro"
                                    call s:MapDelimiters('*', '')
                                elseif a:filetype == "fstab"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "fvwm"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "fx"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "gams"
                                    call s:MapDelimiters('*', '')
                                elseif a:filetype == "gdb"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "gdmo"
                                    call s:MapDelimiters('--', '')
                                elseif a:filetype == "geek"
                                    call s:MapDelimiters('GEEK_COMMENT:', '')
                                elseif a:filetype == "gentoo-conf-d"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "gentoo-env-d"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "gentoo-init-d"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "gentoo-make-conf"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == 'gentoo-package-keywords'
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == 'gentoo-package-mask'
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == 'gentoo-package-use'
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == 'gitAnnotate'
                                    call s:MapDelimiters('', '')
                                elseif a:filetype == 'gitcommit'
                                    call s:MapDelimiters('', '')
                                elseif a:filetype == 'gitconfig'
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == 'gitdiff'
                                    call s:MapDelimiters('', '')
                                elseif a:filetype == "gnuplot"
                                    call s:MapDelimiters('#','')
                                elseif a:filetype == "groovy"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "group"
                                    call s:MapDelimiters('','')
                                elseif a:filetype == "grub"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "gtkrc"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "haskell"
                                    call s:MapDelimitersWithAlternative('{-','-}', '--', '--')
                                elseif a:filetype == "hb"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "h"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "haml"
                                    call s:MapDelimiters('/', '')
                                elseif a:filetype == "help"
                                    call s:MapDelimiters('"','')
                                elseif a:filetype == "hercules"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "hog"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "html"
                                    call s:MapDelimitersWithAlternative('<!--','-->', '//', '')
                                elseif a:filetype == "htmldjango"
                                    call s:MapDelimitersWithAlternative('<!--','-->', '{#', '#}')
                                elseif a:filetype == "htmlos"
                                    call s:MapDelimiters('#','/#')
                                elseif a:filetype == "ia64"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "icon"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "idlang"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "idl"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "indent"
                                    call s:MapDelimiters('/*','*/')
                                elseif a:filetype == "inform"
                                    call s:MapDelimiters('!', '')
                                elseif a:filetype == "inittab"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "ishd"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "iss"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "ist"
                                    call s:MapDelimiters('%', '')
                                elseif a:filetype == "jam"
                                    call s:MapDelimiters('/*','*/')
                                elseif a:filetype == "java"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "javascript"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "jess"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "jgraph"
                                    call s:MapDelimiters('(*','*)')
                                elseif a:filetype == "jproperties"
                                    call s:MapDelimiters('#','')
                                elseif a:filetype == "jsp"
                                    call s:MapDelimiters('<%--', '--%>')
                                elseif a:filetype == "kconfig"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "kix"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "kscript"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "lace"
                                    call s:MapDelimiters('--', '')
                                elseif a:filetype == "ldif"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "lex"
                                    call s:MapDelimiters('/*','*/')
                                elseif a:filetype == "lftp"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "lhaskell"
                                    call s:MapDelimiters('','')
                                elseif a:filetype == "lifelines"
                                    call s:MapDelimiters('/*','*/')
                                elseif a:filetype == "lilo"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "lilypond"
                                    call s:MapDelimiters('%', '')
                                elseif a:filetype == "liquid"
                                    call s:MapDelimiters('{%', '%}')
                                elseif a:filetype == "lisp"
                                    call s:MapDelimitersWithAlternative(';','', '#|', '|#')
                                elseif a:filetype == "lite"
                                    call s:MapDelimiters('/*','*/')
                                elseif a:filetype == "llvm"
                                    call s:MapDelimiters(';','')
                                elseif a:filetype == "lookupfile"
                                    call s:MapDelimiters('', '')
                                elseif a:filetype == "lotos"
                                    call s:MapDelimiters('(*','*)')
                                elseif a:filetype == "lout"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "lprolog"
                                    call s:MapDelimiters('%', '')
                                elseif a:filetype == "lscript"
                                    call s:MapDelimiters("'", '')
                                elseif a:filetype == "lss"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "lua"
                                    call s:MapDelimitersWithAlternative('--','', '--[[', ']]')
                                elseif a:filetype == "lynx"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "lytex"
                                    call s:MapDelimiters('%', '')
                                elseif a:filetype == "m4"
                                    call s:MapDelimiters('dnl ', '')
                                elseif a:filetype == "mail"
                                    call s:MapDelimiters('> ','')
                                elseif a:filetype == "mailcap"
                                    call s:MapDelimiters('#','')
                                elseif a:filetype == "make"
                                    call s:MapDelimiters('#','')
                                elseif a:filetype == "map"
                                    call s:MapDelimiters('%', '')
                                elseif a:filetype == "maple"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "markdown"
                                    call s:MapDelimiters('<!--', '-->')
                                elseif a:filetype == "masm"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "mason"
                                    call s:MapDelimiters('<% #', '%>')
                                elseif a:filetype == "master"
                                    call s:MapDelimiters('$', '')
                                elseif a:filetype == "matlab"
                                    call s:MapDelimiters('%', '')
                                elseif a:filetype == "mel"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "mf"
                                    call s:MapDelimiters('%', '')
                                elseif a:filetype == "mib"
                                    call s:MapDelimiters('--', '')
                                elseif a:filetype == "mkd"
                                    call s:MapDelimiters('>', '')
                                elseif a:filetype == "mma"
                                    call s:MapDelimiters('(*','*)')
                                elseif a:filetype == "modconf"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "model"
                                    call s:MapDelimiters('$','$')
                                elseif a:filetype =~ "moduala."
                                    call s:MapDelimiters('(*','*)')
                                elseif a:filetype == "modula2"
                                    call s:MapDelimiters('(*','*)')
                                elseif a:filetype == "modula3"
                                    call s:MapDelimiters('(*','*)')
                                elseif a:filetype == "monk"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "mplayerconf"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "mrxvtrc"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "mush"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "muttrc"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "named"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "nasm"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "nastran"
                                    call s:MapDelimiters('$', '')
                                elseif a:filetype == "natural"
                                    call s:MapDelimiters('/*', '')
                                elseif a:filetype == "ncf"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "nerdtree"
                                    call s:MapDelimiters('', '')
                                elseif a:filetype == "netdict"
                                    call s:MapDelimiters('', '')
                                elseif a:filetype == "netrw"
                                    call s:MapDelimiters('', '')
                                elseif a:filetype == "nqc"
                                    call s:MapDelimiters('/*','*/')
                                elseif a:filetype == "nroff"
                                    call s:MapDelimiters('\"', '')
                                elseif a:filetype == "nsis"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "objc"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "objcpp"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "ocaml"
                                    call s:MapDelimiters('(*','*)')
                                elseif a:filetype == "occam"
                                    call s:MapDelimiters('--','')
                                elseif a:filetype == "omlet"
                                    call s:MapDelimiters('(*','*)')
                                elseif a:filetype == "omnimark"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "openroad"
                                    call s:MapDelimiters('//', '')
                                elseif a:filetype == "opl"
                                    call s:MapDelimiters("REM", "")
                                elseif a:filetype == "ora"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "otl"
                                    call s:MapDelimiters('', '')
                                elseif a:filetype == "ox"
                                    call s:MapDelimiters('//', '')
                                elseif a:filetype == "pamconf"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "pascal"
                                    call s:MapDelimitersWithAlternative('{','}', '(*', '*)')
                                elseif a:filetype == "passwd"
                                    call s:MapDelimiters('','')
                                elseif a:filetype == "patran"
                                    call s:MapDelimitersWithAlternative('$','','/*', '*/')
                                elseif a:filetype == "pcap"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "pccts"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "perl"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "pfmain"
                                    call s:MapDelimiters('//', '')
                                elseif a:filetype == "php"
                                    call s:MapDelimitersWithAlternative('//','','/*', '*/')
                                elseif a:filetype == "phtml"
                                    call s:MapDelimiters('/*','*/')
                                elseif a:filetype == "pic"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "pike"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "pilrc"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "pine"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "plaintex"
                                    call s:MapDelimiters('%','')
                                elseif a:filetype == "plm"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "plsql"
                                    call s:MapDelimitersWithAlternative('--', '', '/*', '*/')
                                elseif a:filetype == "po"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "postscr"
                                    call s:MapDelimiters('%', '')
                                elseif a:filetype == "pov"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "povini"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "ppd"
                                    call s:MapDelimiters('%', '')
                                elseif a:filetype == "ppwiz"
                                    call s:MapDelimiters(';;', '')
                                elseif a:filetype == "procmail"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "progress"
                                    call s:MapDelimiters('/*','*/')
                                elseif a:filetype == "prolog"
                                    call s:MapDelimitersWithAlternative('%','','/*','*/')
                                elseif a:filetype == "psf"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "ptcap"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "pyrex"
                                    call s:MapDelimiters('#','')
                                elseif a:filetype == "python"
                                    call s:MapDelimiters('#','')
                                elseif a:filetype == "qf"
                                    call s:MapDelimiters('','')
                                elseif a:filetype == "radiance"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "Rails-log"
                                    call s:MapDelimiters('', '')
                                elseif a:filetype == "ratpoison"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "r"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "rc"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "readline"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "rebol"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "registry"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "remind"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "rexx"
                                    call s:MapDelimiters('/*','*/')
                                elseif a:filetype == "rib"
                                    call s:MapDelimiters('#','')
                                elseif a:filetype == "robots"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "rpl"
                                    call s:MapDelimiters('/*','*/')
                                elseif a:filetype == "rst"
                                    call s:MapDelimiters('..', '')
                                elseif a:filetype == "rtf"
                                    call s:MapDelimiters('', '')
                                elseif a:filetype == "ruby"
                                    call s:MapDelimiters('#','')
                                elseif a:filetype == "sa"
                                    call s:MapDelimiters('--','')
                                elseif a:filetype == "samba"
                                    call s:MapDelimitersWithAlternative(';','', '#', '')
                                elseif a:filetype == "sas"
                                    call s:MapDelimiters('/*','*/')
                                elseif a:filetype == "sass"
                                    call s:MapDelimitersWithAlternative('//','', '/*', '')
                                elseif a:filetype == "sather"
                                    call s:MapDelimiters('--', '')
                                elseif a:filetype == "scala"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "scheme"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "scilab"
                                    call s:MapDelimiters('//', '')
                                elseif a:filetype == "screen"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "scsh"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "sdl"
                                    call s:MapDelimiters('/*','*/')
                                elseif a:filetype == "sed"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "selectbuf"
                                    call s:MapDelimiters('', '')
                                elseif a:filetype == "services"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "sgml"
                                    call s:MapDelimiters('<!','>')
                                elseif a:filetype == "sgmldecl"
                                    call s:MapDelimiters('--','--')
                                elseif a:filetype == "sgmllnx"
                                    call s:MapDelimiters('<!--','-->')
                                elseif a:filetype == "sicad"
                                    call s:MapDelimiters('*', '')
                                elseif a:filetype == "simula"
                                    call s:MapDelimitersWithAlternative('%', '', '--', '')
                                elseif a:filetype == "sinda"
                                    call s:MapDelimiters('$', '')
                                elseif a:filetype == "skill"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "slang"
                                    call s:MapDelimiters('%', '')
                                elseif a:filetype == "sl"
                                    call s:MapDelimiters('/*','*/')
                                elseif a:filetype == "slice"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "slrnrc"
                                    call s:MapDelimiters('%', '')
                                elseif a:filetype == "sm"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "smarty"
                                    call s:MapDelimiters('{*', '*}')
                                elseif a:filetype == "smil"
                                    call s:MapDelimiters('<!','>')
                                elseif a:filetype == "smith"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "sml"
                                    call s:MapDelimiters('(*','*)')
                                elseif a:filetype == "snnsnet"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "snnspat"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "snnsres"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "snobol4"
                                    call s:MapDelimiters('*', '')
                                elseif a:filetype == "spec"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "specman"
                                    call s:MapDelimiters('//', '')
                                elseif a:filetype == "spectre"
                                    call s:MapDelimitersWithAlternative('//', '', '*', '')
                                elseif a:filetype == "spice"
                                    call s:MapDelimiters('$', '')
                                elseif a:filetype == "sql"
                                    call s:MapDelimiters('--', '')
                                elseif a:filetype == "sqlforms"
                                    call s:MapDelimiters('--', '')
                                elseif a:filetype == "sqlj"
                                    call s:MapDelimiters('--', '')
                                elseif a:filetype == "sqr"
                                    call s:MapDelimiters('!', '')
                                elseif a:filetype == "squid"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "st"
                                    call s:MapDelimiters('"','')
                                elseif a:filetype == "stata"
                                    call s:MapDelimiters('/*','*/')
                                elseif a:filetype == "stp"
                                    call s:MapDelimiters('--', '')
                                elseif a:filetype == "strace"
                                    call s:MapDelimiters('/*','*/')
                                elseif a:filetype == "sudoers"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "SVKAnnotate"
                                    call s:MapDelimiters('','')
                                elseif a:filetype == "svn"
                                    call s:MapDelimiters('','')
                                elseif a:filetype == "SVNAnnotate"
                                    call s:MapDelimiters('','')
                                elseif a:filetype == "SVNcommitlog"
                                    call s:MapDelimiters('','')
                                elseif a:filetype == "SVNdiff"
                                    call s:MapDelimiters('','')
                                elseif a:filetype == "systemverilog"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "tads"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "taglist"
                                    call s:MapDelimiters('', '')
                                elseif a:filetype == "tags"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "tak"
                                    call s:MapDelimiters('$', '')
                                elseif a:filetype == "tar"
                                    call s:MapDelimiters('', '')
                                elseif a:filetype == "tasm"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "tcl"
                                    call s:MapDelimiters('#','')
                                elseif a:filetype == "terminfo"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "tex"
                                    call s:MapDelimiters('%','')
                                elseif a:filetype == "text"
                                    call s:MapDelimiters('','')
                                elseif a:filetype == "texinfo"
                                    call s:MapDelimiters("@c ", "")
                                elseif a:filetype == "texmf"
                                    call s:MapDelimiters('%', '')
                                elseif a:filetype == "tf"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "tidy"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "tli"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "trasys"
                                    call s:MapDelimiters("$", "")
                                elseif a:filetype == "tsalt"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "tsscl"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "tssgm"
                                    call s:MapDelimiters("comment = '","'")
                                elseif a:filetype == "uc"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "uil"
                                    call s:MapDelimiters('!', '')
                                elseif a:filetype == "vb"
                                    call s:MapDelimiters("'","")
                                elseif a:filetype == "vcscommit"
                                    call s:MapDelimiters('','')
                                elseif a:filetype == "velocity"
                                    call s:MapDelimitersWithAlternative("##","", '#*', '*#')
                                elseif a:filetype == "vera"
                                    call s:MapDelimitersWithAlternative('/*','*/','//','')
                                elseif a:filetype == "verilog"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "verilog_systemverilog"
                                    call s:MapDelimitersWithAlternative('//','', '/*','*/')
                                elseif a:filetype == "vgrindefs"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "vhdl"
                                    call s:MapDelimiters('--', '')
                                elseif a:filetype == "vim"
  400   0.045488   0.008393         call s:MapDelimiters('"','')
  400              0.001604     elseif a:filetype == "viminfo"
                                    call s:MapDelimiters('','')
                                elseif a:filetype == "vimperator"
                                    call s:MapDelimiters('"','')
                                elseif a:filetype == "virata"
                                    call s:MapDelimiters('%', '')
                                elseif a:filetype == "vo_base"
                                    call s:MapDelimiters('', '')
                                elseif a:filetype == "vrml"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "vsejcl"
                                    call s:MapDelimiters('/*', '')
                                elseif a:filetype == "webmacro"
                                    call s:MapDelimiters('##', '')
                                elseif a:filetype == "wget"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype ==? "Wikipedia"
                                    call s:MapDelimiters('<!--','-->')
                                elseif a:filetype == "winbatch"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "wml"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype =~ "[^w]*sh"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "wvdial"
                                    call s:MapDelimiters(';', '')
                                elseif a:filetype == "xdefaults"
                                    call s:MapDelimiters('!', '')
                                elseif a:filetype == "xf86conf"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "xhtml"
                                    call s:MapDelimiters('<!--', '-->')
                                elseif a:filetype == "xkb"
                                    call s:MapDelimiters('//', '')
                                elseif a:filetype == "xmath"
                                    call s:MapDelimiters('#', '')
                                elseif a:filetype == "xml"
                                    call s:MapDelimiters('<!--','-->')
                                elseif a:filetype == "xmodmap"
                                    call s:MapDelimiters('!', '')
                                elseif a:filetype == "xpm2"
                                    call s:MapDelimiters('!', '')
                                elseif a:filetype == "xpm"
                                    call s:MapDelimiters('/*','*/')
                                elseif a:filetype == "xsd"
                                    call s:MapDelimiters('<!--','-->')
                                elseif a:filetype == "xslt"
                                    call s:MapDelimiters('<!--','-->')
                                elseif a:filetype == "yacc"
                                    call s:MapDelimiters('/*','*/')
                                elseif a:filetype == "yaml"
                                    call s:MapDelimiters('#','')
                                elseif a:filetype == "xquery"
                                    call s:MapDelimiters('(:',':)')
                                elseif a:filetype == "z8a"
                                    call s:MapDelimiters(';', '')

                                elseif a:filetype == ""
                                    call s:MapDelimitersWithAlternative("","", "", "")

                                    "we have not hardcoded the comment delimiters to use for this filetype so
                                    "get them from &commentstring.
                                else
                                    "print a disclaimer to the user :)
                                    if !g:NERDShutUp
                                        call s:NerdEcho("Unknown filetype '".a:filetype."', setting delimiters by &commentstring.\nPleeeeease email the author of the NERD commenter with this filetype\nand its delimiters!", 0)
                                    endif

                                    "extract the delims from &commentstring
                                    let left= substitute(&commentstring, '\(.*\)%s.*', '\1', '')
                                    let right= substitute(&commentstring, '.*%s\(.*\)', '\1', 'g')

                                    call s:MapDelimiters(left,right)
                                endif

FUNCTION  System1()
Called 1 time
Total time:   1.094449
 Self time:   0.053694

count  total (s)   self (s)
    1              0.000005     let i=0
  101              0.000906     while i<g:max
  100   1.088993   0.048238         let tmp=system("cat ".shellescape(g:fname))
  100              0.001669         unlet tmp
  100              0.001279         let i+=1
  100              0.000816     endwhile

FUNCTION  <SNR>52_DoModeline()
Called 1200 times
Total time:   9.201255
 Self time:   0.257332

count  total (s)   self (s)
 1200              0.057663     let l:matches = matchlist(a:line, '\%(\S\@<!\%(vi\|vim\([<>=]\?\)\([0-9]\+\)\?\)\|\sex\):\s*set\?\s\+\([^:]\+\):\S\@!')
 1200              0.008853     if len(l:matches) > 0
                                    let l:operator = ">"
                                    if len(l:matches[1]) > 0
                                        let l:operator = l:matches[1]
                                    endif
                                    if len(l:matches[2]) > 0
                                        if <SID>CheckVersion(l:operator, l:matches[2]) ? 0 : 1
                                            return
                                        endif
                                    endif
                                    return <SID>DoSetModeline(l:matches[3])
                                endif

 1200              0.059749     let l:matches = matchlist(a:line, '\%(\S\@<!\%(vi\|vim\([<>=]\?\)\([0-9]\+\)\?\)\|\sex\):\(.\+\)')
 1200              0.008546     if len(l:matches) > 0
  200              0.001084         let l:operator = ">"
  200              0.001865         if len(l:matches[1]) > 0
                                        let l:operator = l:matches[1]
                                    endif
  200              0.001573         if len(l:matches[2]) > 0
                                        if <SID>CheckVersion(l:operator, l:matches[2]) ? 0 : 1
                                            return
                                        endif
                                    endif
  200   8.947552   0.003629         return <SID>DoNoSetModeline(l:matches[3])
                                endif

FUNCTION  Vim1()
Called 1 time
Total time:   7.570761
 Self time:   7.570761

count  total (s)   self (s)
    1              0.000006     let i=0
  101              0.000689     while i < g:max
  100              7.542816         let tmp=join(readfile(g:fname, "b"), "\n")
  100              0.025056         unlet tmp
  100              0.001168         let i+=1
  100              0.000564     endwhile

FUNCTION  Vim3()
Called 1 time
Total time:  10.591508
 Self time:   0.989742

count  total (s)   self (s)
    1              0.000006     let i=0
  101              0.000740     while i < g:max
  100   9.866927   0.568573         execute "view! ".g:fname
  100              0.001851         let savedreg=@a
  100              0.124498         normal! gg"ayG
  100              0.085134         let tmp=@a
  100              0.000801         unlet tmp
  100              0.021234         let @a=savedreg
  100   0.486564   0.183152         bw
  100              0.001098         let i+=1
  100              0.001644     endwhile

FUNCTION  Vim4()
Called 1 time
Total time:   1.170258
 Self time:   0.571477

count  total (s)   self (s)
    1              0.000009     let i=0
  101              0.000627     while i < g:max
  100   0.306459   0.012004         execute "enew!"
  100   0.485735   0.483298         execute "read ".g:fname
  100              0.002363         let savedreg=@a
  100              0.004515         normal! gg"aG
  100              0.000767         let tmp=@a
  100              0.000539         unlet tmp
  100              0.000824         let @a=savedreg
  100   0.366177   0.064288         bw!
  100              0.001042         let i+=1
  100              0.000346     endwhile

Код: Выделить всё

FUNCTIONS SORTED ON TOTAL TIME
count  total (s)   self (s)  function
    1  17.870079   8.309971  Vim2()
  400  14.306784   0.374119  <SNR>3_SynSet()
    1  10.591508   0.989742  Vim3()
  200   9.294414   0.093159  <SNR>52_DoModelines()
 1200   9.201255   0.257332  <SNR>52_DoModeline()
  200   8.943923   0.035807  <SNR>52_DoNoSetModeline()
  800   8.908116   0.094078  <SNR>52_DoOne()
    1   7.570761             Vim1()
 1200   2.686825   2.616208  <SNR>38_SetUpForNewFiletype()
    1   2.000531             Python2()
    1   1.170258   0.571477  Vim4()
    1   1.094449   0.053694  System1()
  400   1.016453   0.337998  <SNR>26_LoadFTPlugin()
  800   0.190413             <SNR>52_IsInList()
  400   0.134854   0.102725  <SNR>28_LoadIndent()
  800   0.070617   0.018863  <SNR>38_MapDelimiters()
  800   0.051754             <SNR>38_MapDelimitersWithAlternative()
  600   0.036820             <SNR>61_LocalBrowse()

FUNCTIONS SORTED ON SELF TIME
count  total (s)   self (s)  function
    1  17.870079   8.309971  Vim2()
    1              7.570761  Vim1()
 1200   2.686825   2.616208  <SNR>38_SetUpForNewFiletype()
    1              2.000531  Python2()
    1  10.591508   0.989742  Vim3()
    1   1.170258   0.571477  Vim4()
  400  14.306784   0.374119  <SNR>3_SynSet()
  400   1.016453   0.337998  <SNR>26_LoadFTPlugin()
 1200   9.201255   0.257332  <SNR>52_DoModeline()
  800              0.190413  <SNR>52_IsInList()
  400   0.134854   0.102725  <SNR>28_LoadIndent()
  800   8.908116   0.094078  <SNR>52_DoOne()
  200   9.294414   0.093159  <SNR>52_DoModelines()
    1   1.094449   0.053694  System1()
  800              0.051754  <SNR>38_MapDelimitersWithAlternative()
  600              0.036820  <SNR>61_LocalBrowse()
  200   8.943923   0.035807  <SNR>52_DoNoSetModeline()
  800   0.070617   0.018863  <SNR>38_MapDelimiters()

(для удобства разделены на две секции).
Вот для vim -u NONE -c source\ test.vim:

Код: Выделить всё

FUNCTION  Vim1()
Called 1 time
Total time:   7.885958
 Self time:   7.885958

count  total (s)   self (s)
    1              0.000009     let i=0
  101              0.000712     while i < g:max
  100              7.855884         let tmp=join(readfile(g:fname, "b"), "\n")
  100              0.026995         unlet tmp
  100              0.001211         let i+=1
  100              0.000645     endwhile

FUNCTION  Vim2()
Called 1 time
Total time:   8.172112
 Self time:   8.172112

count  total (s)   self (s)
    1              0.000006     let i=0
  101              0.000673     while i < g:max
  100              0.220732         execute "view! ".g:fname
  100              7.898790         let tmp=join(getline(0, '$'), "\n")
  100              0.024703         unlet tmp
  100              0.024629         bw
  100              0.001239         let i+=1
  100              0.000525     endwhile

FUNCTION  Vim3()
Called 1 time
Total time:   0.512423
 Self time:   0.512423

count  total (s)   self (s)
    1              0.000008     let i=0
  101              0.000663     while i < g:max
  100              0.247277         execute "view! ".g:fname
  100              0.001569         let savedreg=@a
  100              0.118998         normal! gg"ayG
  100              0.088724         let tmp=@a
  100              0.000806         unlet tmp
  100              0.017132         let @a=savedreg
  100              0.034694         bw
  100              0.001019         let i+=1
  100              0.000518     endwhile

FUNCTION  Vim4()
Called 1 time
Total time:   0.119925
 Self time:   0.119925

count  total (s)   self (s)
    1              0.000006     let i=0
  101              0.000596     while i < g:max
  100              0.005965         execute "enew!"
  100              0.079154         execute "read ".g:fname
  100              0.001367         let savedreg=@a
  100              0.002603         normal! gg"aG
  100              0.000764         let tmp=@a
  100              0.000404         unlet tmp
  100              0.000648         let @a=savedreg
  100              0.026263         bw!
  100              0.000970         let i+=1
  100              0.000370     endwhile

FUNCTION  Python2()
Called 1 time
Total time:   1.986432
 Self time:   1.986432

count  total (s)   self (s)
    1              0.000010     let i=0
  101              0.000667     while i < g:max
  100              0.015335         python fd=open(vim.eval("g:fname"), "rb")
  100              1.945714         python vim.command("let tmp="+simplejson.dumps(fd.read()))
  100              0.017661         python fd.close()
  100              0.004772         unlet tmp
  100              0.001016         let i+=1
  100              0.000529     endwhile

FUNCTION  System1()
Called 1 time
Total time:   1.064951
 Self time:   0.089093

count  total (s)   self (s)
    1              0.000009     let i=0
  101              0.000892     while i<g:max
  100   1.059645   0.083787         let tmp=system("cat ".shellescape(g:fname))
  100              0.001564         unlet tmp
  100              0.001194         let i+=1
  100              0.000837     endwhile

Код: Выделить всё

FUNCTIONS SORTED ON TOTAL TIME
count  total (s)   self (s)  function
    1   8.172112             Vim2()
    1   7.885958             Vim1()
    1   1.986432             Python2()
    1   1.064951   0.089093  System1()
    1   0.512423             Vim3()
    1   0.119925             Vim4()

FUNCTIONS SORTED ON SELF TIME
count  total (s)   self (s)  function
    1              8.172112  Vim2()
    1              7.885958  Vim1()
    1              1.986432  Python2()
    1              0.512423  Vim3()
    1              0.119925  Vim4()
    1   1.064951   0.089093  System1()


Спрашивал затем, что точное положение Python2 в первом тесте (без отмены
инициализации) нестабильно.

PS: В «пустом» сообщении было то же, что и в этом, но с цитатой .

UPD: Перед этим сообщением мне удалось запостить отоброжавшееся пустым. Видимо,
оно уже исчезло.
Спасибо сказали:
Аватара пользователя
ZyX
Сообщения: 355
ОС: Gentoo

Re: VIM + JSON: загрузка файла в переменную

Сообщение ZyX »

Новая модификация теста способов загрузки содержимого файлов в переменную:

Код: Выделить всё

let g:max=100
let g:fname="/home/zyx/.vim/plugin/translit3.vim"
python import vim
python import simplejson
python import demjson
python import re
function Python2()
    let i=0
    while i < g:max
        python fd=open(vim.eval("g:fname"), "rb")
        python vim.command("let tmp="+simplejson.dumps(fd.read()))
        python fd.close()
        unlet tmp
        let i+=1
    endwhile
endfunction
function Vim1()
    let i=0
    while i < g:max
        let tmp=join(readfile(g:fname, "b"), "\n")
        unlet tmp
        let i+=1
    endwhile
endfunction
function Vim2()
    let i=0
    while i < g:max
        let savedei=&eventignore
        set eventignore=all
        execute "view! ".g:fname
        let tmp=join(getline(0, '$'), "\n")
        unlet tmp
        bwipeout
        let &eventignore=savedei
        unlet savedei
        let i+=1
    endwhile
endfunction
function Vim3()
    let i=0
    while i < g:max
        let savedei=&eventignore
        set eventignore=all
        execute "view! ".g:fname
        let savedreg=@a
        normal! gg"ayG
        let tmp=@a
        unlet tmp
        let @a=savedreg
        bwipeout
        let &eventignore=savedei
        unlet savedei
        let i+=1
    endwhile
endfunction
function Vim4()
    let i=0
    while i < g:max
        let savedei=&eventignore
        set eventignore=all
        execute "enew!"
        execute "read ".g:fname
        let savedreg=@a
        normal! gg"aG
        let tmp=@a
        unlet tmp
        let @a=savedreg
        bwipeout!
        let &eventignore=savedei
        unlet savedei
        let i+=1
    endwhile
endfunction
function System1()
    let i=0
    while i<g:max
        let tmp=system("cat ".shellescape(g:fname))
        unlet tmp
        let i+=1
    endwhile
endfunction
profile start lprofile
profile func *
echo "python2"
call Python2()
echo "vim1"
call Vim1()
echo "vim2"
call Vim2()
echo "vim3"
call Vim3()
echo "vim4"
call Vim4()
echo "system1"
call System1()
qa!

Добавлена установка eventignore в all перед загрузкой файлов. System больше не
обгоняет ни Vim3, ни Vim4, но Vim4 при запуске с «-u NONE» выдаёт такую
ошибку:

Код: Выделить всё

E812: Autocommands changed buffer or buffer name
E484: Невозможно открыть файл /home/zyx/.vim/plugin/translit3.vim

, что очень странно, так как никаких автокоманд не существует.
Результаты:
vim -c source\ test.vim

Код: Выделить всё

FUNCTION  Python2()
Called 1 time
Total time:   2.017100
 Self time:   2.017100

count  total (s)   self (s)
    1              0.000010     let i=0
  101              0.000726     while i < g:max
  100              0.022007         python fd=open(vim.eval("g:fname"), "rb")
  100              1.975263         python vim.command("let tmp="+simplejson.dumps(fd.read()))
  100              0.015859         python fd.close()
  100              0.000976         unlet tmp
  100              0.000987         let i+=1
  100              0.000536     endwhile

FUNCTION  Vim2()
Called 1 time
Total time:   8.513189
 Self time:   8.513189

count  total (s)   self (s)
    1              0.000007     let i=0
  101              0.001456     while i < g:max
  100              0.000673         let savedei=&eventignore
  100              0.001116         set eventignore=all
  100              0.579522         execute "view! ".g:fname
  100              7.830725         let tmp=join(getline(0, '$'), "\n")
  100              0.026350         unlet tmp
  100              0.068079         bwipeout
  100              0.002270         let &eventignore=savedei
  100              0.000517         unlet savedei
  100              0.000730         let i+=1
  100              0.000561     endwhile

FUNCTION  System1()
Called 1 time
Total time:   1.044198
 Self time:   0.053751

count  total (s)   self (s)
    1              0.000006     let i=0
  101              0.000824     while i<g:max
  100   1.038672   0.048225         let tmp=system("cat ".shellescape(g:fname))
  100              0.001869         unlet tmp
  100              0.001168         let i+=1
  100              0.000806     endwhile

FUNCTION  Vim1()
Called 1 time
Total time:   8.283940
 Self time:   8.283940

count  total (s)   self (s)
    1              0.000006     let i=0
  101              0.000751     while i < g:max
  100              8.253912         let tmp=join(readfile(g:fname, "b"), "\n")
  100              0.026952         unlet tmp
  100              0.001167         let i+=1
  100              0.000657     endwhile

FUNCTION  Vim3()
Called 1 time
Total time:   0.898678
 Self time:   0.898678

count  total (s)   self (s)
    1              0.000007     let i=0
  101              0.000661     while i < g:max
  100              0.000656         let savedei=&eventignore
  100              0.001117         set eventignore=all
  100              0.578035         execute "view! ".g:fname
  100              0.002166         let savedreg=@a
  100              0.124573         normal! gg"ayG
  100              0.088922         let tmp=@a
  100              0.000862         unlet tmp
  100              0.016414         let @a=savedreg
  100              0.080240         bwipeout
  100              0.002019         let &eventignore=savedei
  100              0.000486         unlet savedei
  100              0.000675         let i+=1
  100              0.000535     endwhile

FUNCTION  Vim4()
Called 1 time
Total time:   0.633472
 Self time:   0.633472

count  total (s)   self (s)
    1              0.000006     let i=0
  101              0.000633     while i < g:max
  100              0.000653         let savedei=&eventignore
  100              0.001996         set eventignore=all
  100              0.012014         execute "enew!"
  100              0.531999         execute "read ".g:fname
  100              0.002402         let savedreg=@a
  100              0.004772         normal! gg"aG
  100              0.000822         let tmp=@a
  100              0.000505         unlet tmp
  100              0.000817         let @a=savedreg
  100              0.072018         bwipeout!
  100              0.001937         let &eventignore=savedei
  100              0.000552         unlet savedei
  100              0.000667         let i+=1
  100              0.000492     endwhile

FUNCTIONS SORTED ON TOTAL TIME
count  total (s)   self (s)  function
    1   8.513189             Vim2()
    1   8.283940             Vim1()
    1   2.017100             Python2()
    1   1.044198   0.053751  System1()
    1   0.898678             Vim3()
    1   0.633472             Vim4()

FUNCTIONS SORTED ON SELF TIME
count  total (s)   self (s)  function
    1              8.513189  Vim2()
    1              8.283940  Vim1()
    1              2.017100  Python2()
    1              0.898678  Vim3()
    1              0.633472  Vim4()
    1   1.044198   0.053751  System1()

vim -u NONE -c source\ test.vim

Код: Выделить всё

FUNCTION  Vim1()
Called 1 time
Total time:   7.590350
 Self time:   7.590350

count  total (s)   self (s)
    1              0.000006     let i=0
  101              0.000732     while i < g:max
  100              7.561241         let tmp=join(readfile(g:fname, "b"), "\n")
  100              0.026054         unlet tmp
  100              0.001194         let i+=1
  100              0.000598     endwhile

FUNCTION  Vim2()
Called 1 time
Total time:   7.674958
 Self time:   7.674958

count  total (s)   self (s)
    1              0.000007     let i=0
  101              0.000611     while i < g:max
  100              0.000578         let savedei=&eventignore
  100              0.001203         set eventignore=all
  100              0.230814         execute "view! ".g:fname
  100              7.389663         let tmp=join(getline(0, '$'), "\n")
  100              0.025307         unlet tmp
  100              0.022371         bwipeout
  100              0.001821         let &eventignore=savedei
  100              0.000403         unlet savedei
  100              0.000647         let i+=1
  100              0.000537     endwhile

FUNCTION  Vim3()
Called 1 time
Total time:   0.467147
 Self time:   0.467147

count  total (s)   self (s)
    1              0.000006     let i=0
  101              0.000540     while i < g:max
  100              0.000619         let savedei=&eventignore
  100              0.001159         set eventignore=all
  100              0.216635         execute "view! ".g:fname
  100              0.001395         let savedreg=@a
  100              0.110891         normal! gg"ayG
  100              0.084231         let tmp=@a
  100              0.000710         unlet tmp
  100              0.014458         let @a=savedreg
  100              0.032564         bwipeout
  100              0.001376         let &eventignore=savedei
  100              0.000394         unlet savedei
  100              0.000574         let i+=1
  100              0.000468     endwhile

FUNCTION  Vim4()
Called 1 time
Total time:   0.112318
 Self time:   0.112318

count  total (s)   self (s)
    1              0.000005     let i=0
  101              0.000570     while i < g:max
  100              0.000649         let savedei=&eventignore
  100              0.001003         set eventignore=all
  100              0.006530         execute "enew!"
  100              0.061121         execute "read ".g:fname
  100              0.001498         let savedreg=@a
  100              0.002550         normal! gg"aG
  100              0.000691         let tmp=@a
  100              0.000408         unlet tmp
  100              0.000715         let @a=savedreg
  100              0.031390         bwipeout!
  100              0.002501         let &eventignore=savedei
  100              0.000462         unlet savedei
  100              0.000636         let i+=1
  100              0.000421     endwhile

FUNCTION  Python2()
Called 1 time
Total time:   1.979708
 Self time:   1.979708

count  total (s)   self (s)
    1              0.000011     let i=0
  101              0.000738     while i < g:max
  100              0.014516         python fd=open(vim.eval("g:fname"), "rb")
  100              1.945437         python vim.command("let tmp="+simplejson.dumps(fd.read()))
  100              0.015808         python fd.close()
  100              0.001026         unlet tmp
  100              0.000946         let i+=1
  100              0.000513     endwhile

FUNCTION  System1()
Called 1 time
Total time:   1.154212
 Self time:   0.165896

count  total (s)   self (s)
    1              0.000005     let i=0
  101              0.001070     while i<g:max
  100   1.148770   0.160454         let tmp=system("cat ".shellescape(g:fname))
  100              0.001547         unlet tmp
  100              0.001210         let i+=1
  100              0.000833     endwhile

FUNCTIONS SORTED ON TOTAL TIME
count  total (s)   self (s)  function
    1   7.674958             Vim2()
    1   7.590350             Vim1()
    1   1.979708             Python2()
    1   1.154212   0.165896  System1()
    1   0.467147             Vim3()
    1   0.112318             Vim4()

FUNCTIONS SORTED ON SELF TIME
count  total (s)   self (s)  function
    1              7.674958  Vim2()
    1              7.590350  Vim1()
    1              1.979708  Python2()
    1              0.467147  Vim3()
    1   1.154212   0.165896  System1()
    1              0.112318  Vim4()

Спасибо сказали:
Аватара пользователя
ZyX
Сообщения: 355
ОС: Gentoo

Re: VIM + JSON: загрузка файла в переменную

Сообщение ZyX »

Так как вопрос возник ещё раз, здесь другие результаты исследования (новый vim, больше функций, используемый файл — одна 7‐мебибайтная строка):

Решения на python и с использованием readfile выпали, так как я не смог дождаться их завершения (> 1 минуты неприемлимо ⇒ нет смысла их тестировать).

vim‐7.3.322, linux:

Код:

FUNCTION Vim_buf_yank() Called 1 time Total time: 0.691734 Self time: 0.691734 count total (s) self (s) 1 0.000002 let i=0 3 0.000009 while i < g:max 2 0.000005 let savedei=&eventignore 2 0.000011 set eventignore=all 2 0.681571 execute "silent tab sview ".g:fname 2 0.000033 let savedreg=@a 2 0.008419 silent %yank 2 0.000022 let tmp=@a 2 0.000006 unlet tmp 2 0.000011 let @a=savedreg 2 0.001569 bwipeout 2 0.000023 let &eventignore=savedei 2 0.000003 unlet savedei 2 0.000006 let i+=1 2 0.000005 endwhile FUNCTION System1() Called 1 time Total time: 0.084921 Self time: 0.015845 count total (s) self (s) 1 0.000002 let i=0 3 0.000013 while i<g:max 2 0.084839 0.015763 let tmp=system("cat ".shellescape(g:fname)) 2 0.000020 unlet tmp 2 0.000013 let i+=1 2 0.000009 endwhile FUNCTION Vim_read_yank() Called 1 time Total time: 0.453668 Self time: 0.453668 count total (s) self (s) 1 0.000002 let i=0 3 0.000008 while i < g:max 2 0.000006 let savedei=&eventignore 2 0.000011 set eventignore=all 2 0.000193 execute "silent tabnew" 2 0.440952 execute "silent read ".g:fname 2 0.000033 let savedreg=@a 2 0.009132 silent %yank 2 0.000032 let tmp=@a 2 0.000008 unlet tmp 2 0.000011 let @a=savedreg 2 0.003188 bwipeout! 2 0.000030 let &eventignore=savedei 2 0.000004 unlet savedei 2 0.000007 let i+=1 2 0.000006 endwhile FUNCTION Vim_read_normal_yank() Called 1 time Total time: 1.181807 Self time: 1.181807 count total (s) self (s) 1 0.000003 let i=0 3 0.000008 while i < g:max 2 0.000007 let savedei=&eventignore 2 0.000011 set eventignore=all 2 0.000186 execute "silent tabnew" 2 0.450064 execute "silent read ".g:fname 2 0.000032 let savedreg=@a 2 0.715448 silent normal! gg"ayG 2 0.012764 let tmp=@a 2 0.000014 unlet tmp 2 0.000018 let @a=savedreg 2 0.003154 bwipeout! 2 0.000028 let &eventignore=savedei 2 0.000003 unlet savedei 2 0.000005 let i+=1 2 0.000016 endwhile FUNCTION Vim_buf_getline() Called 1 time Total time: 0.880467 Self time: 0.880467 count total (s) self (s) 1 0.000005 let i=0 3 0.000012 while i < g:max 2 0.000009 let savedei=&eventignore 2 0.000012 set eventignore=all 2 0.835605 execute "silent tab sview ".g:fname 2 0.041226 let tmp=join(getline(0, '$'), "\n") 2 0.001420 unlet tmp 2 0.002085 bwipeout 2 0.000035 let &eventignore=savedei 2 0.000004 unlet savedei 2 0.000006 let i+=1 2 0.000007 endwhile FUNCTION Vim_buf_normal_yank() Called 1 time Total time: 0.735652 Self time: 0.735652 count total (s) self (s) 1 0.000002 let i=0 3 0.000010 while i < g:max 2 0.000006 let savedei=&eventignore 2 0.000012 set eventignore=all 2 0.693333 execute "silent tab sview ".g:fname 2 0.000041 let savedreg=@a 2 0.026938 silent normal! gg"ayG 2 0.012275 let tmp=@a 2 0.000013 unlet tmp 2 0.000024 let @a=savedreg 2 0.002910 bwipeout 2 0.000028 let &eventignore=savedei 2 0.000005 unlet savedei 2 0.000006 let i+=1 2 0.000006 endwhile FUNCTIONS SORTED ON TOTAL TIME count total (s) self (s) function 1 1.181807 Vim_read_normal_yank() 1 0.880467 Vim_buf_getline() 1 0.735652 Vim_buf_normal_yank() 1 0.691734 Vim_buf_yank() 1 0.453668 Vim_read_yank() 1 0.084921 0.015845 System1() FUNCTIONS SORTED ON SELF TIME count total (s) self (s) function 1 1.181807 Vim_read_normal_yank() 1 0.880467 Vim_buf_getline() 1 0.735652 Vim_buf_normal_yank() 1 0.691734 Vim_buf_yank() 1 0.453668 Vim_read_yank() 1 0.084921 0.015845 System1()


gvim‐7.3.353, windows (XP, в виртуалке):

Код:

FUNCTION Vim_read_normal_yank() Called 1 time Total time: 9.741687 Self time: 9.741687 count total (s) self (s) 1 0.000008 let i=0 3 0.000019 while i < g:max 2 0.002647 execute 'silent tabnew +setl\ noswapfile' 2 8.878265 execute "silent read ".g:fname 2 0.002016 let savedreg=@a 2 0.794056 silent normal! gg"ayG 2 0.056836 let tmp=@a 2 0.001394 unlet tmp 2 0.001390 let @a=savedreg 2 0.003722 bwipeout! 2 0.000022 let i+=1 2 0.000012 endwhile FUNCTION Vim_buf_getline() Called 1 time Total time: 5.345580 Self time: 5.345580 count total (s) self (s) 1 0.000009 let i=0 3 0.000021 while i < g:max 2 5.070339 execute 'silent tab sview '.g:fname 2 0.269372 let tmp=join(getline(0, '$'), "\n") 2 0.001093 unlet tmp 2 0.004450 bwipeout 2 0.000025 let i+=1 2 0.000011 endwhile FUNCTION Vim_buf_yank() Called 1 time Total time: 5.259453 Self time: 5.259453 count total (s) self (s) 1 0.000007 let i=0 3 0.000019 while i < g:max 2 5.160585 execute 'silent tab sview '.g:fname 2 0.000852 let savedreg=@a 2 0.093999 silent %yank 2 0.000047 let tmp=@a 2 0.000013 unlet tmp 2 0.000019 let @a=savedreg 2 0.003662 bwipeout 2 0.000024 let i+=1 2 0.000011 endwhile FUNCTION Vim_buf_normal_yank() Called 1 time Total time: 5.470005 Self time: 5.470005 count total (s) self (s) 1 0.000006 let i=0 3 0.000018 while i < g:max 2 5.257621 execute 'silent tab sview '.g:fname 2 0.000783 let savedreg=@a 2 0.110762 silent normal! gg"ayG 2 0.093760 let tmp=@a 2 0.001612 unlet tmp 2 0.001460 let @a=savedreg 2 0.003819 bwipeout 2 0.000022 let i+=1 2 0.000011 endwhile FUNCTION Vim_read_yank() Called 1 time Total time: 8.917966 Self time: 8.917966 count total (s) self (s) 1 0.000008 let i=0 3 0.000028 while i < g:max 2 0.002760 execute 'silent tabnew +setl\ noswapfile' 2 8.834308 execute "silent read ".g:fname 2 0.002967 let savedreg=@a 2 0.071623 silent %yank 2 0.000115 let tmp=@a 2 0.000067 unlet tmp 2 0.000061 let @a=savedreg 2 0.003776 bwipeout! 2 0.000039 let i+=1 2 0.000023 endwhile FUNCTION System_shelltemp() Called 1 time Total time: 7.571016 Self time: 0.094303 count total (s) self (s) 1 0.000008 let i=0 1 0.000010 set shelltemp 3 0.000019 while i<g:max 2 7.569113 0.092400 let tmp=system("cat ".shellescape(g:fname)) 2 0.001751 unlet tmp 2 0.000027 let i+=1 2 0.000013 endwhile FUNCTION System_noshelltemp() Called 1 time Total time: 7.443322 Self time: 0.101295 count total (s) self (s) 1 0.000009 let i=0 1 0.000010 set noshelltemp 3 0.000020 while i<g:max 2 7.440325 0.098298 let tmp=system("cat ".shellescape(g:fname)) 2 0.001743 unlet tmp 2 0.000028 let i+=1 2 0.000012 endwhile FUNCTIONS SORTED ON TOTAL TIME count total (s) self (s) function 1 9.741687 Vim_read_normal_yank() 1 8.917966 Vim_read_yank() 1 7.571016 0.094303 System_shelltemp() 1 7.443322 0.101295 System_noshelltemp() 1 5.470005 Vim_buf_normal_yank() 1 5.345580 Vim_buf_getline() 1 5.259453 Vim_buf_yank() FUNCTIONS SORTED ON SELF TIME count total (s) self (s) function 1 9.741687 Vim_read_normal_yank() 1 8.917966 Vim_read_yank() 1 5.470005 Vim_buf_normal_yank() 1 5.345580 Vim_buf_getline() 1 5.259453 Vim_buf_yank() 1 7.443322 0.101295 System_noshelltemp() 1 7.571016 0.094303 System_shelltemp()


Здесь обновлённые результаты для файла со множеством строк (vim-7.3.322, linux):

Код:

FUNCTION Vim_buf_yank() Called 1 time Total time: 0.147103 Self time: 0.147103 count total (s) self (s) 1 0.000003 let i=0 101 0.000195 while i < g:max 100 0.000234 let savedei=&eventignore 100 0.000325 set eventignore=all 100 0.099927 execute "silent tab sview ".g:fname 100 0.000429 let savedreg=@a 100 0.041392 silent %yank 100 0.000287 let tmp=@a 100 0.000139 unlet tmp 100 0.000288 let @a=savedreg 100 0.002718 bwipeout 100 0.000411 let &eventignore=savedei 100 0.000133 unlet savedei 100 0.000206 let i+=1 100 0.000142 endwhile FUNCTION System1() Called 1 time Total time: 1.789159 Self time: 0.023830 count total (s) self (s) 1 0.000002 let i=0 101 0.000379 while i<g:max 100 1.786657 0.021328 let tmp=system("cat ".shellescape(g:fname)) 100 0.000824 unlet tmp 100 0.000547 let i+=1 100 0.000437 endwhile FUNCTION Vim_read_yank() Called 1 time Total time: 0.164450 Self time: 0.164450 count total (s) self (s) 1 0.000002 let i=0 101 0.000221 while i < g:max 100 0.000253 let savedei=&eventignore 100 0.000368 set eventignore=all 100 0.006902 execute "silent tabnew" 100 0.100666 execute "silent read ".g:fname 100 0.000649 let savedreg=@a 100 0.045147 silent %yank 100 0.000281 let tmp=@a 100 0.000158 unlet tmp 100 0.000301 let @a=savedreg 100 0.008104 bwipeout! 100 0.000592 let &eventignore=savedei 100 0.000160 unlet savedei 100 0.000217 let i+=1 100 0.000153 endwhile FUNCTION Python2() Called 1 time Total time: 0.405710 Self time: 0.405710 count total (s) self (s) 1 0.000007 let i=0 101 0.000237 while i < g:max 100 0.005836 python fd=open(vim.eval("g:fname"), "rb") 100 0.392282 python vim.command("let tmp="+json.dumps(fd.read())) 100 0.004997 python fd.close() 100 0.001542 unlet tmp 100 0.000391 let i+=1 100 0.000220 endwhile FUNCTION Vim_read_normal_yank() Called 1 time Total time: 0.182639 Self time: 0.182639 count total (s) self (s) 1 0.000002 let i=0 101 0.000215 while i < g:max 100 0.000260 let savedei=&eventignore 100 0.000349 set eventignore=all 100 0.008150 execute "silent tabnew" 100 0.102875 execute "silent read ".g:fname 100 0.000663 let savedreg=@a 100 0.034285 silent normal! gg"ayG 100 0.017248 let tmp=@a 100 0.000204 unlet tmp 100 0.005148 let @a=savedreg 100 0.011804 bwipeout! 100 0.000620 let &eventignore=savedei 100 0.000151 unlet savedei 100 0.000223 let i+=1 100 0.000145 endwhile FUNCTION Vim_buf_getline() Called 1 time Total time: 1.682846 Self time: 1.682846 count total (s) self (s) 1 0.000002 let i=0 101 0.000232 while i < g:max 100 0.000252 let savedei=&eventignore 100 0.000361 set eventignore=all 100 0.100951 execute "silent tab sview ".g:fname 100 1.566005 let tmp=join(getline(0, '$'), "\n") 100 0.009715 unlet tmp 100 0.003899 bwipeout 100 0.000595 let &eventignore=savedei 100 0.000140 unlet savedei 100 0.000247 let i+=1 100 0.000153 endwhile FUNCTION Vim_buf_normal_yank() Called 1 time Total time: 0.166505 Self time: 0.166505 count total (s) self (s) 1 0.000002 let i=0 101 0.000203 while i < g:max 100 0.000246 let savedei=&eventignore 100 0.000333 set eventignore=all 100 0.100060 execute "silent tab sview ".g:fname 100 0.000450 let savedreg=@a 100 0.032718 silent normal! gg"ayG 100 0.018136 let tmp=@a 100 0.000180 unlet tmp 100 0.005624 let @a=savedreg 100 0.007294 bwipeout 100 0.000475 let &eventignore=savedei 100 0.000145 unlet savedei 100 0.000207 let i+=1 100 0.000147 endwhile FUNCTION Vim_readfile() Called 1 time Total time: 1.595955 Self time: 1.595955 count total (s) self (s) 1 0.000002 let i=0 101 0.000231 while i < g:max 100 1.585301 let tmp=join(readfile(g:fname, "b"), "\n") 100 0.009758 unlet tmp 100 0.000326 let i+=1 100 0.000187 endwhile FUNCTIONS SORTED ON TOTAL TIME count total (s) self (s) function 1 1.789159 0.023830 System1() 1 1.682846 Vim_buf_getline() 1 1.595955 Vim_readfile() 1 0.405710 Python2() 1 0.182639 Vim_read_normal_yank() 1 0.166505 Vim_buf_normal_yank() 1 0.164450 Vim_read_yank() 1 0.147103 Vim_buf_yank() FUNCTIONS SORTED ON SELF TIME count total (s) self (s) function 1 1.682846 Vim_buf_getline() 1 1.595955 Vim_readfile() 1 0.405710 Python2() 1 0.182639 Vim_read_normal_yank() 1 0.166505 Vim_buf_normal_yank() 1 0.164450 Vim_read_yank() 1 0.147103 Vim_buf_yank() 1 1.789159 0.023830 System1()
Спасибо сказали:
Аватара пользователя
ZyX
Сообщения: 355
ОС: Gentoo

Re: VIM + JSON: загрузка файла в переменную

Сообщение ZyX »

Проверочный файл на github: https://gist.github.com/1569146
Спасибо сказали:
Аватара пользователя
ZyX
Сообщения: 355
ОС: Gentoo

Re: VIM + JSON: загрузка файла в переменную

Сообщение ZyX »

Новые данные: во‐первых, в каком‐то патче исправили join(), из‐за чего этот способ стал почти самым быстрым (5‐е место). Во‐вторых, после моих патчей с улучшениями интерфейса между vim и python способы, использующие новые функции заняли первые четыре места, причём самым быстрым оказалось использование pyeval():

Код: Выделить всё

FUNCTIONS SORTED ON TOTAL TIME
count  total (s)   self (s)  function
    1   0.158383             Python3()
    1   0.104078   0.012087  System_shelltemp()
    1   0.096691             Python2()
    1   0.084489   0.014481  System_noshelltemp()
    1   0.032442   0.028323  Vim_buf_normal_yank()
    1   0.031329             Vim_readfile_binary()
    1   0.031309   0.028038  Vim_buf_yank()
    1   0.030742             Vim_buf_getline()
    1   0.030636   0.027492  Vim_read_normal_yank()
    1   0.030367   0.027170  Vim_read_yank()
    1   0.024999             Vim_readfile()
    1   0.007285             Python3_bindeval()
    1   0.006195             Python2_bindeval()
    1   0.003986             Py3eval()
    1   0.003503             Pyeval()

FUNCTIONS SORTED ON SELF TIME
count  total (s)   self (s)  function
    1              0.158383  Python3()
    1              0.096691  Python2()
    1              0.031329  Vim_readfile_binary()
    1              0.030742  Vim_buf_getline()
    1   0.032442   0.028323  Vim_buf_normal_yank()
    1   0.031309   0.028038  Vim_buf_yank()
    1   0.030636   0.027492  Vim_read_normal_yank()
    1   0.030367   0.027170  Vim_read_yank()
    1              0.024999  Vim_readfile()
    1   0.084489   0.014481  System_noshelltemp()
    1   0.104078   0.012087  System_shelltemp()
    1              0.007285  Python3_bindeval()
    1              0.006195  Python2_bindeval()
    1              0.003986  Py3eval()
    1              0.003503  Pyeval()

. Из профиля выше удалена функция Diff. Полный профиль ниже:

Код:

FUNCTION Python2_bindeval() Called 1 time Total time: 0.006195 Self time: 0.006195 count total (s) self (s) 1 0.000045 python import vim 1 0.000004 let i=0 5 0.000012 while i < g:max 4 0.000296 python fd=open(vim.eval("g:fname"), "rb") 4 0.004583 python vim.bindeval('l:')['tmp']=str(fd.read()) 4 0.000244 python fd.close() 4 0.000977 Fin 4 0.000017 endwhile FUNCTION Python3_bindeval() Called 1 time Total time: 0.007285 Self time: 0.007285 count total (s) self (s) 1 0.000061 py3 import vim 1 0.000003 let i=0 5 0.000013 while i < g:max 4 0.000370 py3 fd=open(vim.eval("g:fname"), "rb") 4 0.005232 py3 vim.bindeval('l:')['tmp']=bytes(fd.read()) 4 0.000275 py3 fd.close() 4 0.001308 Fin 4 0.000006 endwhile FUNCTION System_shelltemp() Called 1 time Total time: 0.104078 Self time: 0.012087 count total (s) self (s) 1 0.000003 let i=0 1 0.000004 set shelltemp 5 0.000033 while i<g:max 4 0.100861 0.008870 let tmp=system("cat ".shellescape(g:fname)) 4 0.003072 Fin 4 0.000036 endwhile FUNCTION Vim_readfile_binary() Called 1 time Total time: 0.031329 Self time: 0.031329 count total (s) self (s) 1 0.000003 let i=0 5 0.000012 while i < g:max 4 0.029544 let tmp=join(readfile(g:fname, "b"), "\n") 4 0.001746 Fin 4 0.000008 endwhile FUNCTION System_noshelltemp() Called 1 time Total time: 0.084489 Self time: 0.014481 count total (s) self (s) 1 0.000008 let i=0 1 0.000020 set noshelltemp 5 0.000042 while i<g:max 4 0.081260 0.011252 let tmp=system("cat ".shellescape(g:fname)) 4 0.003052 Fin 4 0.000033 endwhile FUNCTION Diff() Called 4 times Total time: 0.013731 Self time: 0.013731 count total (s) self (s) 4 0.000026 if &modified tabnew endif 4 0.000015 let e1=1 4 0.001822 if a:tmp[-1:] isnot# "\n" let e1=0 endif 4 0.000012 let e2=1 4 0.001485 if a:reference[-1:] isnot# "\n" 4 0.000013 let e2=0 4 0.000004 endif 4 0.000009 if e1 != e2 4 0.009928 if a:tmp[:-1-e1] is# a:reference[:-1-e2] 4 0.000341 echom "Only end of line differs" 4 0.000014 return else echom "End of line differs" endif endif call setline(1, split(a:tmp, "\n", 1)) diffthis vertical new call setline(1, split(a:reference, "\n", 1)) file `=expand("<sfile>")` diffthis FUNCTION Vim_buf_getline() Called 1 time Total time: 0.030742 Self time: 0.030742 count total (s) self (s) 1 0.000002 let i=0 5 0.000011 while i < g:max 4 0.000016 let savedei=&eventignore 4 0.000030 set eventignore=all 4 0.020042 execute "silent tab sview ".fnameescape(g:fname) 4 0.008814 let tmp=join(getline(0, '$'), "\n") 4 0.000746 bwipeout 4 0.000053 let &eventignore=savedei 4 0.000008 unlet savedei 4 0.000975 Fin 4 0.000007 endwhile FUNCTION Vim_buf_normal_yank() Called 1 time Total time: 0.032442 Self time: 0.028323 count total (s) self (s) 1 0.000002 let i=0 5 0.000013 while i < g:max 4 0.000015 let savedei=&eventignore 4 0.000025 set eventignore=all 4 0.020122 execute "silent tab sview ".fnameescape(g:fname) 4 0.000028 let savedreg=@a 4 0.003357 silent normal! gg"ayG 4 0.002219 let tmp=@a 4 0.000677 let @a=savedreg 4 0.000264 bwipeout 4 0.000030 let &eventignore=savedei 4 0.000009 unlet savedei 4 0.005630 0.001511 Fin 4 0.000015 endwhile FUNCTION Pyeval() Called 1 time Total time: 0.003503 Self time: 0.003503 count total (s) self (s) 1 0.000002 let i=0 5 0.000010 while i < g:max 4 0.002497 let tmp=pyeval('str(open(vim.eval("g:fname"), "rb").read())') 4 0.000973 Fin 4 0.000006 endwhile FUNCTION Vim_buf_yank() Called 1 time Total time: 0.031309 Self time: 0.028038 count total (s) self (s) 1 0.000003 let i=0 5 0.000015 while i < g:max 4 0.000019 let savedei=&eventignore 4 0.000025 set eventignore=all 4 0.019738 execute "silent tab sview ".fnameescape(g:fname) 4 0.000027 let savedreg=@a 4 0.003372 silent %yank a 4 0.002209 let tmp=@a 4 0.000669 let @a=savedreg 4 0.000304 bwipeout 4 0.000032 let &eventignore=savedei 4 0.000011 unlet savedei 4 0.004836 0.001565 Fin 4 0.000014 endwhile FUNCTION Python2() Called 1 time Total time: 0.096691 Self time: 0.096691 count total (s) self (s) 1 0.020016 python import vim 1 0.000016 let i=0 5 0.000016 while i < g:max 4 0.000312 python fd=open(vim.eval("g:fname"), "rb") 4 0.074991 python vim.eval("extend(l:, {'tmp': '"+(fd.read().replace("'", "''"))+"'})") 4 0.000357 python fd.close() 4 0.000954 Fin 4 0.000009 endwhile FUNCTION Python3() Called 1 time Total time: 0.158383 Self time: 0.158383 count total (s) self (s) 1 0.049122 py3 import vim 1 0.000015 let i=0 5 0.000021 while i < g:max 4 0.000445 py3 fd=open(vim.eval("g:fname"), "rb") 4 0.105076 py3 vim.eval(str(b"extend(l:, {'tmp': '"+(fd.read().replace(b"'", b"''"))+b"'})", "utf-8")) 4 0.000518 py3 fd.close() 4 0.003138 Fin 4 0.000024 endwhile FUNCTION Py3eval() Called 1 time Total time: 0.003986 Self time: 0.003986 count total (s) self (s) 1 0.000003 let i=0 5 0.000012 while i < g:max 4 0.002644 let tmp=py3eval('bytes(open(vim.eval("g:fname"), "rb").read())') 4 0.001309 Fin 4 0.000007 endwhile FUNCTION Vim_read_normal_yank() Called 1 time Total time: 0.030636 Self time: 0.027492 count total (s) self (s) 1 0.000002 let i=0 5 0.000014 while i < g:max 4 0.000017 let savedei=&eventignore 4 0.000025 set eventignore=all 4 0.000443 execute "silent tabnew" 4 0.018582 execute "silent read ".fnameescape(g:fname) 4 0.000046 silent 1d _ 4 0.000025 let savedreg=@a 4 0.003216 silent normal! gg"ayG 4 0.002202 let tmp=@a 4 0.000660 let @a=savedreg 4 0.000612 bwipeout! 4 0.000032 let &eventignore=savedei 4 0.000010 unlet savedei 4 0.004700 0.001556 Fin 4 0.000007 endwhile FUNCTION Vim_read_yank() Called 1 time Total time: 0.030367 Self time: 0.027170 count total (s) self (s) 1 0.000002 let i=0 5 0.000012 while i < g:max 4 0.000016 let savedei=&eventignore 4 0.000024 set eventignore=all 4 0.000443 execute "silent tabnew" 4 0.018540 execute "silent read ".fnameescape(g:fname) 4 0.000041 silent 1d _ 4 0.000023 let savedreg=@a 4 0.003048 silent %yank a 4 0.002194 let tmp=@a 4 0.000634 let @a=savedreg 4 0.000575 bwipeout! 4 0.000035 let &eventignore=savedei 4 0.000010 unlet savedei 4 0.004727 0.001530 Fin 4 0.000008 endwhile FUNCTION Vim_readfile() Called 1 time Total time: 0.024999 Self time: 0.024999 count total (s) self (s) 1 0.000003 let i=0 5 0.000011 while i < g:max 4 0.022534 let tmp=join(readfile(g:fname), "\n") 4 0.002429 Fin 4 0.000007 endwhile FUNCTIONS SORTED ON TOTAL TIME count total (s) self (s) function 1 0.158383 Python3() 1 0.104078 0.012087 System_shelltemp() 1 0.096691 Python2() 1 0.084489 0.014481 System_noshelltemp() 1 0.032442 0.028323 Vim_buf_normal_yank() 1 0.031329 Vim_readfile_binary() 1 0.031309 0.028038 Vim_buf_yank() 1 0.030742 Vim_buf_getline() 1 0.030636 0.027492 Vim_read_normal_yank() 1 0.030367 0.027170 Vim_read_yank() 1 0.024999 Vim_readfile() 4 0.013731 Diff() 1 0.007285 Python3_bindeval() 1 0.006195 Python2_bindeval() 1 0.003986 Py3eval() 1 0.003503 Pyeval() FUNCTIONS SORTED ON SELF TIME count total (s) self (s) function 1 0.158383 Python3() 1 0.096691 Python2() 1 0.031329 Vim_readfile_binary() 1 0.030742 Vim_buf_getline() 1 0.032442 0.028323 Vim_buf_normal_yank() 1 0.031309 0.028038 Vim_buf_yank() 1 0.030636 0.027492 Vim_read_normal_yank() 1 0.030367 0.027170 Vim_read_yank() 1 0.024999 Vim_readfile() 1 0.084489 0.014481 System_noshelltemp() 4 0.013731 Diff() 1 0.104078 0.012087 System_shelltemp() 1 0.007285 Python3_bindeval() 1 0.006195 Python2_bindeval() 1 0.003986 Py3eval() 1 0.003503 Pyeval()

Спасибо сказали:
Ответить