LINUX.ORG.RU

[lisp][/r/]Нужна IDE

 


0

2

Начинаю изучать Common Lisp. Хотелось бы найти удобную среду разработки. Сейчас использую Geany для Python'а и Code::Blocks для C++, иногда Vim для обоих. Приветствуется нечто похожее на Geany, в идеале - плагин для оного. FAQ читал, Emacs использовать не хочу.



Последнее исправление: Hetor (всего исправлений: 1)

Ответ на: комментарий от Love5an

вообще, __int8 это некая виндово-специфичная декларация, насколько я понимаю.

Love5an
()
Ответ на: комментарий от korvin_

>вы никогда не кончитесь?
Разумеется, ведь человеку, не знающему внутренней кухни лиспового-рантайма-или-чего-у-него-там, сложно объяснить, зачем писать в бинарь весь имидж, а не его выжимки, необходимые для работы только данного кода.

GAMer ★★★★★
()
Ответ на: комментарий от Love5an

Не прошло и месяца, как у меня дошли руки до этого теста. Итак:

bubblesort.cpp:

#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <time.h>
#include <vector>
#include <iostream>
 
typedef __uint8_t u8;
template<typename T>
inline void swap(T& a, T& b)
{
    T temp(a);
    a=b;
    b=temp;
}
/*
void bubble_sort_(std::vector<u8>& v, int start, int end)
{
    bool swapped;
    do
    {
        swapped = false;
        for(int i = start; i<(end-1); ++i)
            if(v[i] > v[i+1])
            {
                swap(v[i], v[i+1]);
                swapped = true;
            }
    }while(swapped);
}
*/
typedef std::vector<u8>::iterator iter;
void bubble_sort(const iter begin, const iter end)
{
    bool swapped;
    do
    {
        swapped = false;
        for(iter i = begin; i!=(end-1); ++i)
            if(*i > *(i+1))
            {
                swap(*i, *(i+1));
                swapped = true;
            }
    }while(swapped);
}

int main(int argc, char** argv)
{
    if(argc>3 || argc<2)
    {
        std::cout << "Usage: bubble_sort n [print_result]" << std::endl;
        return 0;
    }
    size_t n, print_result = 0;
    if(!(n=strtoul(argv[1], NULL, 10)))
    {
        std::cout << "Invalid input" << std::endl;
        return 1;
    }
    if(3 == argc)
    {
        print_result = argv[2][0]=='y' || argv[2][0]=='Y';
    }
    std::vector<u8> v(n);
    for(size_t i = 0; i<n; ++i)
        v.at(i)=(n-i-1)%256;
    clock_t t = clock();
    bubble_sort(v.begin(),v.end());
    std::cout << (clock()-t)/1.0/CLOCKS_PER_SEC << " seconds" << std::endl;
    if(print_result)
    {
        for(size_t i = 0; i<n; ++i)
            std::cout << static_cast<int>(v.at(i)) << ' ';
        std::cout << std::endl;
    }
    return 0;
}

bublesort.lisp:

(declaim (optimize (speed 3) (space 0) (safety 0) (debug 0)))

(deftype u8 () '(unsigned-byte 8))

(defun bubble-sort (v start end)
  (declare (type fixnum start end)           
           (type (simple-array u8 (*)) v))
  (loop :for swapped :of-type boolean = nil
        :do (loop :for i fixnum :from start :below (1- end)
                  :do (when (> (aref v i) (aref v (1+ i)))
                        (rotatef (aref v i) (aref v (1+ i)))
                        (setf swapped t)))
        :while swapped))

(defun main (&optional (n (parse-integer (second sb-ext:*posix-argv*)))
                       (print-result (when (third sb-ext:*posix-argv*)
                                       (let ((*read-eval* nil))
                                         (read-from-string
                                           (third sb-ext:*posix-argv*))))))
  (declare (type fixnum n))
  (let ((v (make-array n :element-type 'u8)))
    (dotimes (i n)
      (setf (aref v i) (mod (- n i 1) 256)) )
    (time (bubble-sort v 0 n))
    (when print-result
      (loop :for b :across v :do (format t "~a " b)
            :finally (terpri)))))

;(main 100000)

Что получилось:

[legolegs@battlehummer bubblesort]$ make clean run
rm -f bubblesort.lisp.exe bubblesort.cpp.O2.exe bubblesort.cpp.O3.exe
./compile.lisp

; compiling file "/home/legolegs/programing/bubblesort/bubblesort.lisp" (written 15 JUL 2010 09:07:23 AM):
; compiling (DECLAIM (OPTIMIZE # ...))
; compiling (DEFTYPE U8 ...)
; compiling (DEFUN BUBBLE-SORT ...)
; compiling (DEFUN MAIN ...)

; /home/legolegs/programing/bubblesort/bubblesort.fasl written
; compilation finished in 0:00:00.061
[undoing binding stack and other enclosing state... done]
[saving current Lisp image into bubblesort.lisp.exe:
writing 6352 bytes from the read-only space at 0x20000000
writing 4064 bytes from the static space at 0x20100000
writing 47628288 bytes from the dynamic space at 0x1000000000
done]
g++ -O2 -Wold-style-cast -Wstrict-aliasing -Wall -Wextra -Weffc++ -Wsign-conversion -Warray-bounds -Wswitch-default -Wswitch-enum -Wpointer-arith -Wcast-align -Wcast-qual -Wwrite-strings -Wlogical-op -Wmissing-noreturn -Winline -pedantic -std=c++0x --strict-aliasing -fwhole-program -DNDEBUG -s -o bubblesort.cpp.O2.exe bubblesort.cpp
g++ -O3 -Wold-style-cast -Wstrict-aliasing -Wall -Wextra -Weffc++ -Wsign-conversion -Warray-bounds -Wswitch-default -Wswitch-enum -Wpointer-arith -Wcast-align -Wcast-qual -Wwrite-strings -Wlogical-op -Wmissing-noreturn -Winline -pedantic -std=c++0x --strict-aliasing -fwhole-program -DNDEBUG -s -o bubblesort.cpp.O3.exe bubblesort.cpp
./bubblesort.lisp.exe 100000
Evaluation took:
  28.135 seconds of real time
  27.291851 seconds of total run time (27.279853 user, 0.011998 system)
  97.00% CPU
  56,452,280,080 processor cycles
  0 bytes consed
  
./bubblesort.cpp.O2.exe 100000
15.52 seconds
./bubblesort.cpp.O3.exe 100000
14.52 seconds

[legolegs@battlehummer bubblesort]$ gcc --version
gcc (GCC) 4.4.3 20100127 (Red Hat 4.4.3-4)
Copyright (C) 2010 Free Software Foundation, Inc.
Это свободно распространяемое программное обеспечение. Условия копирования
приведены в исходных текстах. Без гарантии каких-либо качеств, включая 
коммерческую ценность и применимость для каких-либо целей.

[legolegs@battlehummer bubblesort]$ sbcl --version
SBCL 1.0.38-2.fc12

[legolegs@battlehummer bubblesort]$ cat /proc/cpuinfo | grep name | uniq
model name      : Intel(R) Core(TM)2 CPU          4400  @ 2.00GHz
итого 46M

[legolegs@battlehummer bubblesort]$ ll
-rwxr-x--- 1 legolegs legolegs  12K Июл  4 17:39 bubblesort
-rw-r----- 1 legolegs legolegs 1,8K Июл 15 20:32 bubblesort.cpp
-rwxr-x--- 1 legolegs legolegs 6,2K Июл 16 08:42 bubblesort.cpp.O2.exe
-rwxr-x--- 1 legolegs legolegs 6,2K Июл 16 08:42 bubblesort.cpp.O3.exe
-rw-r----- 1 legolegs legolegs 5,1K Июл 16 08:42 bubblesort.fasl
-rw-r----- 1 legolegs legolegs 1,2K Июл 15 09:07 bubblesort.lisp
-rwxr-xr-x 1 legolegs legolegs  46M Июл 16 08:42 bubblesort.lisp.exe
-rw-r----- 1 legolegs legolegs  62K Июл  4 19:22 bubblesort.png
-rwxr-x--- 1 legolegs legolegs  229 Июл 15 20:17 compile.lisp
-rw-r----- 1 legolegs legolegs  890 Июл 16 08:41 Makefile
-rw-r----- 1 legolegs legolegs 4,2K Июл 16 08:48 report.txt

Двухкратное преимущество налицо. Лисповый бинарник бесспорно жирен, но сравнивать надо с gcc -static, иначе это ни о чём не говорит.

PS интересно, что 32хбитная версия (т.е. g++ -m32) ещё быстрее, времена порядка 11.45 секунд.

legolegs ★★★★★
()
Ответ на: комментарий от legolegs

> но сравнивать надо с gcc -static, иначе это ни о чём не говорит.

получится 12K + 1.2Mb, хотя libstdc++ нет смысла линковать статично - для любых дистрибутивов( даже андроида ) - она есть гарантированно, т.к. от нее зависят многие базовые библиотеки и программы

ahonimous
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.