среда, 27 июля 2011 г.

Linux - Mono System.Collections.Generic

Dictionary<int, int> t = new Dictionary<int, int> ();

Заполнение
1218
902
865
863
873

Чтение
239
220
228
224
220

Linux - Java Collections Framework

Java Collections Framework vs Colt vs Trove vs PCJ vs Fastutil

Java Collections Framework
Map<Integer, Integer> t = new HashMap <Integer, Integer> ();

Colt 1.2.0
OpenIntIntHashMap t = new OpenIntIntHashMap ();

Trove 3.0.0rc2
TIntIntHashMap t = new TIntIntHashMap ();

PCJ 1.2
IntKeyIntOpenHashMap t = new IntKeyIntOpenHashMap ();


Fastutil 6.3
Int2IntOpenHashMap t = new Int2IntOpenHashMap ();


Кол-во тестов: 5
Цикл: 10000000

Результаты в миллисекундах
Заполнение
JCFColtTrovePCJFastutil
1162711758817841688
903112539507221734
788212528817141675
10463100810357241703
4581106510406111780

Чтение
JCFColtTrovePCJFastutil
21161197669907
4435966357888
2052937156898
3889917056903
2131927155962

JCF
Colt

Trove
PCJ
Fastutil


пятница, 22 июля 2011 г.

Linux - python

Python

Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40)
[GCC 4.4.5] on linux2

import datetime

def test():
    c = 100000000
   
    for i in range(0, c):
    x = i / 10

for i in range (0, 5):
    s = datetime.datetime.now()
    test ()
    e = datetime.datetime.now()
   
    print e-s

0:00:10.153447
0:00:09.966268
0:00:09.965614
0:00:09.964048
0:00:09.982430

Результаты

Linux Debian 6
java
5
1
0
0
0

Erlang
2185
2162
2160
2158
2190

Basic
870
867
860
860
860

Pascal
323
316
315
314
314

Mono
510
511
510
511
510

Bash
24167
24141
24112
24069
24080
C=1000000
MySql
35660
-
-
-
-
C=10000000
Ruby
36462
36558
36718
36677
36511

C++
321
316
317
324
314

C
318
284
281
287
281

PHP
25652
25643
26877
27133
25590

ActionScript3
393
424
419
393
404

JavaScript Firefox 5
963
972
984
946
948

JavaScript Opera 11.50
993
982
996
989
973

JavaScript Google Chrome 12.0.742.124
897
894
894
894
894

JavaScript Firefox 3.6.13
7621
7596
7588
7586
7598

Python
10153
9966
9965
9964
9982

Windows 7
Java
5
2
0
0
0

C
361
328
328
329
328

C++
347
347
347
348
347
G++
C++
86
78
77
77
77
BCC
C++
2164
2147
2153
2149
2144
DMC
PHP
11440
11550
11500
11510
11480

JS Firefox 5.0
1905
1900
1902
1905
1899

JS Firefox 3.6.17
797
792
793
796
794

JS Chrome 12.0.742.122
1126
1110
1112
1113
1110

JS Internet Explorer 9 (9.0.8112.16421)
244
199
202
204
203

JS Internet Explorer 9 (9.0.8112.16421) 64-bit Edition
7865
7856
8040
8212
8405

JS Opera 11.50 сборка 1074
911
901
913
908
908

Oberon-2
8039
8043
8046
8030
8039
Oxford Oberon-2

Linux - erlang

Erlang
Erlang (BEAM) emulator version 5.8
Compiled on Sun Dec  5 19:07:34 2010

-module(testerl).
-export([main/1]).

main(5)->
    io:format("end");
main(N)->
    S=now_milli(erlang:now()),
    testr(0),
    E=now_milli(erlang:now()),
   
    io:format("r= ~w ~n", [E-S]),
    main(N+1).
   
testr(100000000)->
    1;
testr(N) ->
    X=N/10,
    testr(N+1).

now_milli({MegaSecs,Secs,MicroSecs}) ->
        (MegaSecs*1000000 + Secs)*1000 + MicroSecs/1000.


2185.85498046875
2162.136962890625
2160.8369140625
2158.656982421875
2190.274169921875

вторник, 19 июля 2011 г.

Linux - basic

Basic
FreeBASIC Compiler - Version 0.22.0 (05-06-2011) for linux (target:linux)

declare sub test()

DIM As Integer i

for i=1 to 5
    test ()
next i

sub test ()
    DIM As Integer i
    DIM As Integer x
    DIM As double s
    DIM As double e
    DIM As double r
   
    s = Timer
    for i=1 to 100000000
    x = i / 10
    next i
    e = Timer
   
    r = (e - s) * 1000
    print r
end sub

Запуск:
> fbc testbasic.bas
> ./testbasic

Результат:
870.2189922332764
867.264986038208
860.558032989502
860.0380420684814
860.3219985961914

Linux - pascal

Pascal
Free Pascal Compiler version 2.4.0-2 [2010/02/20] for i386

uses
    BaseUnix, Unix;
var
t:longint;

function GetTickCount: Cardinal; stdcall;
var
  t: timeval;
begin
  fpgettimeofday(@t, nil);
  GetTickCount := t.tv_sec * 1000 + t.tv_usec div 1000;
end;

PROCEDURE test;
var
    x,i,s,e:longint;
    max:longint=100000000;
begin
    s := GetTickCount;
    for i:=0 to max do
    begin
    x := i div 10;
    end;
    e := GetTickCount;
    Writeln (e-s);
end;


begin
    for t:=1 to 5 do
    begin
    test;
    end;
end.

Запуск:
> fpc testpascal.p
> ./testpascal

Результаты:
323
316
315
314
314

Linux - mono

Mono
Mono C# compiler version 2.6.7.0

using System;

namespace testn
{
    public class TestClass
    {
        public static void Main()
        {
            for (int i = 0; i < 5; i++)
                test ();
        }
       
        public static void test ()
        {
            long s = System.Environment.TickCount;
            int count = 100000000;
            for (int i=0; i < count; ++i)
            {
                int x = i/10;
            }
            long e = System.Environment.TickCount;
            Console.WriteLine(e-s);
        }
    }
}

> mcs testc#.cs
> ./testc#.exe

510
511
510
511
510

Linux - bash

Bash
GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)



#!/bin/bash

t=0
while [ $t -lt 5 ]
do
    s=$(($(date +%s%N)/1000000))
    i=0
    x=0
    while [ $i -lt 1000000 ]
    do
 x=$[$i/10]
 i=$[$i+1]
    done
    
    e=$(($(date +%s%N)/1000000))
    r=$[$e-$s]
    echo $r
    t=$[$t+1]
done
 
24167
24141
24112
24069
24080

Linux - mysql

MySql 
5.1.49-3

Ждать результат для 100 000 000 не оказалось возможности.

BEGIN
DECLARE i INT DEFAULT 0;
DECLARE x INT DEFAULT 0;

    WHILE i < 10000000 DO
        SET x = i / 10;
        SET i = i+1;
    END WHILE;
END

mysql> delimeter //
mysql> create procedure `test`()  begin declare i int default 0; declare x int default 0; while i < 10000000 do set x = i / 10; set i = i+1; end while; end ;//
Query OK, 0 rows affected (0.00 sec)

mysql> call test ();//
Query OK, 0 rows affected (35.66 sec)

Linux - ruby

Ruby
ruby 1.8.7 (2010-08-16 patchlevel 302) [i486-linux]

def test ()
    n= 100000000
    1.upto(n) {|i| x = i / 10}
end

1.upto(5) {|i|
    s = Time.now.to_f
    test()
    e = Time.now.to_f
    p(i, (e-s))
}

Запуск:
>ruby testruby.rb

Результат (секунды):
1
36.4624440670013
2
36.5586810112
3
36.7188448905945
4
36.6779959201813
5
36.5112500190735

суббота, 16 июля 2011 г.

Windows–ход конём

Железо: AMD Phenom(tm) II X4 810 Processor @ 2.60 ГГц
ОС: Windows 7 Максимальная
И как всегда не без сюрпризов, на этот раз удивил Internet Explorer 9.

ЯП №1 №2 №3 №4 №5 Версия
Java 5 2 0 0 0 java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)
C 361 328 328 329 328 gcc.EXE (GCC) 4.5.2
C++ 347 347 347 348 347 g++.EXE (GCC) 4.5.2
C++ 86 78 77 77 77 Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
C++ 2164 2147 2153 2149 2144 Digital Mars Compiler Version 8.42n
PHP 11.44s 11.55s 11.50s 11.51s 11.48s PHP 5.3.3 (cli) (built: Jul 21 2010 20:36:55)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
JS 1905 1900 1902 1905 1899 Mozilla Firefox 5.0
JS 797 792 793 796 794 Mozilla Firefox 3.6.17
JS 1126 1110 1112 1113 1110 Google Chrome 12.0.742.122
JS 244 199 202 204 203 Internet Explorer 9 (9.0.8112.16421)
JS 7865 7856 8040 8212 8405 Internet Explorer 9 (9.0.8112.16421) 64-bit Edition
JS 911 901 913 908 908 Opera 11.50 сборка 1074
Oberon-2 8039 8043 8046 8030 8039 Oxford Oberon-2 compiler version 2.5.1

 

Upd:

Код

С++

#include <sys/timeb.h>
#include <stdio.h>

void test ()
{
struct timeb start, end;

   ftime(&start);
   int count = 100000000;
   for (int i=0; i < count; ++i)
      int x = i/10;
   ftime(&end);

long mtime = ((end.time - start.time) * 1000 + end.millitm - start.millitm);
   printf("%ld\n", mtime);
}
int main (void)
{
   for (int i=0; i < 5; i++)
      test ();
}

 

Oberon-2

MODULE testo2;

IMPORT Timer, Out;

VAR
    t:INTEGER;

PROCEDURE test;
VAR
    s,e,i,max:INTEGER;
    x:REAL;
BEGIN
    max := 100000000;
    i := 0;
    s := Timer.Now();
    WHILE i < max DO i := i+1; x:=i / 10; END;
    e := Timer.Now();
    Out.Int (e-s, 1);
    Out.Ln;
END test;

BEGIN
    t:=0;
    WHILE t < 5 DO t := t+1; test END;
END testo2.

пятница, 15 июля 2011 г.

Первый бой

Священная война начинается со спора, в споре рождается истина, спор перерастает во флейм, истина замещается всякой ложью. И это забавно. А теперь добавим забаве абсурда. Это абсурдный тест заимствованный от сюда http://habrahabr.ru/blogs/programming/120090/ 
Результаты указаны в миллисекундах, кроме тех где указано иное.


Среда
CPU: Intel(R) Pentium(R) CPU G6950 @ 2.80ГГц

ОС: Debian 6.0.2 (x86)



JAVA
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Запуск из Eclipse Helios

public class MathTest{
  public static void main (String[] args){
    for (int i =0; i < 5; i++)
      test ();
    }
  static public void test (){
    long s = System.currentTimeMillis();
    int cout = 100000000;
    for (int i = 0; i < cout; ++i){
      int x = i / 10;
    }
    long e = System.currentTimeMillis();
    System.out.println (e-s);
  }
}


результат:
5
1
0
0
0



C++
g++ (Debian 4.4.5-8) 4.4.5

запуск:
> g++ testcpp.cpp
> a.out

#include <sys/time.h>
#include <stdio.h>
#include <unistd.h>
void test ()
{
  struct timeval start, end;
  long mtime, seconds, useconds;
  gettimeofday(&start, NULL);
  int count = 100000000;
  for (int i=0; i < count; ++i)
    int x = i/10;
  gettimeofday(&end, NULL);
  seconds = end.tv_sec - start.tv_sec;
  useconds = end.tv_usec - start.tv_usec;
  mtime = ((seconds) * 1000 + useconds/1000.0) + 0.5;
  printf("%ld\n", mtime);
}
int main (void)
{
  for (int i=0; i < 5; i++)
    test ();
}

результат:
321
316
317
324
314



C
gcc (Debian 4.4.5-8) 4.4.5


запуск:
> gcc testc.cpp
> a.out

#include <sys/time.h>
#include <stdio.h>
#include <unistd.h>
void test ()
{
  struct timeval start, end;
  long mtime, seconds, useconds;
  int count, i, x;
  gettimeofday(&start, NULL);
  count = 100000000;
  for (i=0; i < count; ++i)
    x = i/10;
  gettimeofday(&end, NULL);
  seconds = end.tv_sec - start.tv_sec;
  useconds = end.tv_usec - start.tv_usec;
  mtime = ((seconds) * 1000 + useconds/1000.0) + 0.5;
  printf("%ld\n", mtime);
}
int main (void)
{
  int i;
  for (i=0; i < 5; i++)
    test ();
}

результат:
318
284
281
287
281



PHP
PHP 5.3.3-7+squeeze3 with Suhosin-Patch (cli) (built: Jun 28 2011 13:13:26)


запуск:
> php -f testphp.php

<?php
  for($i = 0; $i < 5; $i++)
    test ();
  function test ()
  {
    $s = microtime (true);
    $count = 100000000;
    for ($i=0; $i<$count; ++$i)
      $x = $i / 10;
    $e = microtime (true);
    echo ($e-$s) . "\n";
}
?>

результат (секунды):
25.652865171432
25.643960952759
26.877197980881
27.133295059204
25.590247154236



ActionScript 3
Linux Flash Player 10.3 Projector (10.3.181.34)


запуск:
> mxmlc testflex.mxml
> flashplayer testflex.swf

mxmlc Version 4.5.1 build 21328
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml" layout="absolute"
width="300" height="300" initialize="main()" backgroundAlpha="0">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
public function main():void
{
  for (var i:Number=0; i < 5; i++)
    test();
}
public function test():void
{
  var s : Number = new Date ().time;
  var count: Number = 100000000;
  for (var i:Number =0; i < count; ++i)
    var x: Number = i/ 10;
  var e: Number = new Date ().time;
  var r :Number = e-s;
  Alert.show (String(r));
}
]]>
</mx:Script>
</mx:Application>


результат:
393
424
419
393
404



JavaScript

запуск:
Открыть файл\testjs.html

<script>
for (var t=0; t<5;t++)
  test ();
function test ()
{
  var s = new Date ().getTime();
  var count = 100000000;
  for (var i=0; i< count; ++i)
    var x = i/10;
  var e = new Date().getTime();
  document.write ((e-s));
  document.write("<br>");
}
</script>

результаты по браузерам:
Firefox 5.0
963
972
984
946
948


Opera 11.50
993
982
996
989
973


Google Chrome 12.0.742.124
897
894
894
894
894



// Нетрадиционные извращения

Firefox 3.6.13
7621
7596
7588
7586
7598


PlayOnLinux Internet Explorer 7
завис



// Вне. Замеры любезно предоставленные
Python

результат (секунды):
35


P.S. Обожаю php и js в браузерах,