Harbour Teste de Velocidade.

Projeto [x]Harbour - Compilador de código aberto compatível com o Clipper.

Moderador: Moderadores

Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7928
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Re: Harbour Teste de Velocidade.

Mensagem por Itamar M. Lins Jr. »

Repare que o icc ganha em velocidade do msvc. Mas será que compensa usar o icc ao invés o msvc ?
Bom para responder essas dúvidas é o Maligno. Mas eu penso que o MSVC tem mais estrada é roda no OS do mesmo dono, documentação farta, entre outras coisas, e a MS não vai querer perder "Market Share" para ninguém.

Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
Hasse
Usuário Nível 4
Usuário Nível 4
Mensagens: 820
Registrado em: 19 Out 2004 10:30
Localização: Jaraguá do Sul - SC

Re: Harbour Teste de Velocidade.

Mensagem por Hasse »

A versão 1.2.0 (rev6400) do xHarbour já tem o MAKE_VC.BAT para compilar com o MSVC. Vejam o cabeçalho dele:
rem ============================================================================
rem
rem $Id: make_vc.bat,v 1.25 2008/10/18 17:08:54 ronpinkas Exp $
rem
rem FILE: make_vc.bat
rem BATCH FILE FOR MSVC
rem
rem This is Generic File, do not change it. If you should require your own build
rem version, changes should only be made on your local copy.(AJ:2008-04-26)
rem
rem ============================================================================

Também o MAKE_GC.BAT para compilar com o MINGW32, como abaixo:
rem ============================================================================
rem
rem $Id: make_gc.bat,v 1.15 2009/01/27 03:00:36 guerra000 Exp $
rem
rem FILE: make_gc.bat
rem BATCH FILE FOR MINGW32
rem
rem This is Generic File, do not change it. If you should require your own build
rem version, changes should only be made on your local copy.(AJ:2008-04-26)
rem
rem ============================================================================
Hasse
CP200 / CP500 / Basic / dBase III / dBase IV / Clipper Summer / RTlink / Exospace.
Clipper 5.3b / Blinker 7.0 / CDX com TAG
xHarbour 1.2.1-6604 / Borland C++ (5.5.1) 32 bit / HBmake.
Harbour 3.2.0dev (r1412121623) / MINGW / HBM2 / MiniGui HMG 3.1.4 / IDE (Roberto Lopez).
"Conheça todas as teorias, domine todas as técnicas, mas, quando tocares uma alma humana, seja apenas outra alma humana." (C.G.Jung)
Avatar do usuário
Maligno
Membro Master
Membro Master
Mensagens: 6398
Registrado em: 06 Jul 2004 01:40
Localização: Londrina/PR

Re: Harbour Teste de Velocidade.

Mensagem por Maligno »

Itamar M. Lins Jr. escreveu:Bom para responder essas dúvidas é o Maligno.
Não sei porque eu, mas...

Não conheço o ICC, mas já ouvi falar muito bem. Aí entra um fator de peso, que nesse benchmark não aparece: confiabilidade. Desses compiladores eu só uso o BCC e o GCC. O BCC é extremamente confiável. Nunca vi qualquer problema nele. Por outro lado, o GCC já me deu um bocado de trabalho com bugs absurdos e inexplicáveis. Outro dia, por exemplo, uma função estava modificando uma variável local na função chamadora. Ou seja, totalmente fora de escopo. Algo absolutamente impossível. Mas acontecia. Eu me certifiquei disso. Não resolvi. Nem tem como resolver algo do tipo. Apenas fiz uma gambiarra pra mudar a "forma" do código. Tempos depois, voltei tudo ao que era e o erro misteriosamente sumiu, sem trocar a versão do compilador. Só uso o GCC pra coisa realmente pequena, em C puro, e de forma bem vigiada.

Logo, mais importante que velocidade, é a confiabilidade. Ademais, o que vemos nesse benchmark é o resultado de algum tipo de processamento, para sabermos qual compilador tem um otimizador melhor em determinada situação, que não é a situação mais comum que nós, desenvolvedores de sistemas administrativos, vemos no nosso dia-a-dia. Ou seja, testa-se o núcleo do software em uma situação ímpar, mas sem levar em conta o que realmente nos interessa, que é a camada mais externa do software e que, pra maioria deste fórum, é muito mais importante. Para o tipo de software que desenvolvemos temos muito mais manipulação de entradas e saídas em disco que processamento bruto. Logo, esse teste não tem lá muito valor. O BCC é tão rápido quanto o VC. Os dois conseguem otimizações excelentes. Se programasse em [x]Harbour certamente me manteria com o BCC, porque já uso. Mas poderia sem problema aconselhar alguém a usar o VC, que é excelente. Agora, pra botar software no cliente, eu JAMAIS usaria o GCC.

Nisso há outro aspecto: mesmo os compiladores sendo muito otimizados, as empresas que os produzem tem suas diferenças. Ao passo que a MS tem um run-time embutido em cada Windows (utilizado também pelo GCC e outros), a Borland não. A Borland (hoje Codegear) tem um run-time exclusivo, o que justifica o fato dos executáveis produzidos pelo BCC serem maiores. Claro que hoje em dia o tamanho do executável não é lá uma grande preocupação, mas algumas pessoas levam isso em conta. Acredito que as diferenças de tempos entre os dois venham dessa diferença de run-time. Mas, como eu disse, pra mim esse dado é irrelevante.

Uma curiosidade: faltou informar que fonte foi compilado, o que ele levou em consideração, quais os comandos de linha de cada compilador, quem o fez, que metodologia a pessoa usou, etc. O que vimos são apenas números. Já vi benchmark parecido em que não houve preocupação em utilizar uma metodologia apropriada. Certa vez ganhei uma boa dor abdominal rindo demais de um programador Delphi que fez um teste do tipo entre o Delphi e Assembly. Ele chegou à incrível conclusão que o Delphi é muito mais rápido. Mas nem demonstrou o teste. Claro. Então, a capacidade de quem fez o teste e a qualidade do teste são dados tão importantes quanto o resultado. Sem isso, os números são apenas números.

Finalizando a análise: eu não produzo carros de corrida. Produzo software. Velocidade máxima, cuja diferença é mínima em relação ao que tenho, não me garante boas vendas. O que garante o dinheiro entrando é a satisfação dos clientes quanto aos recursos que ofereço no meu software. Por isso nunca dei a menor importância pra esse tipo de teste. Se eu tiver confiabilidade, já me considero plenamente satisfeito.

Se tivesse que dar um conselho aos colegas, eu diria: desencanem dessa história de velocidade. Isso não é tão importante quanto parece.
[]'s
Maligno
---
Não respondo questões técnicas através de MP ou eMail. Não insista.
As dúvidas devem ser postadas no fórum. Desta forma, todos poderão
se beneficiar das respostas.

---
Se um dia precisar de uma transfusão de sangue você perceberá como
é importante a figura do doador. Procure o hemocentro de sua cidade e
se informe sobre a doação de sangue, plaquetas e medula óssea. Doe!
Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7928
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Re: Harbour Teste de Velocidade.

Mensagem por Itamar M. Lins Jr. »

Uma curiosidade: faltou informar que fonte foi compilado, o que ele levou em consideração, quais os comandos de linha de cada compilador, quem o fez, que metodologia a pessoa usou, etc.
Código abaixo, usado tambem com demais compiladores.
Nesse caso especifico o Harbour compilado com BCC em Multi thread.

Código: Selecionar todos

03/19/09 13:56:08 Windows XP 5.1.2600 Service Pack 3
Harbour 1.1.0dev (Rev. 10650) (MT) Borland C++ 5.5.1 (32-bit)
THREADS: 0
N_LOOPS: 1000000
[ T000: empty loop overhead ]...................................0.06
====================================================================
[ T001: x := L_C ]..............................................0.16
[ T002: x := L_N ]..............................................0.05
[ T003: x := L_D ]..............................................0.05
[ T004: x := S_C ]..............................................0.17
[ T005: x := S_N ]..............................................0.08
[ T006: x := S_D ]..............................................0.08
[ T007: x := M->M_C ]...........................................0.20
[ T008: x := M->M_N ]...........................................0.09
[ T009: x := M->M_D ]...........................................0.09
[ T010: x := M->P_C ]...........................................0.20
[ T011: x := M->P_N ]...........................................0.11
[ T012: x := M->P_D ]...........................................0.09
[ T013: x := F_C ]..............................................0.56
[ T014: x := F_N ]..............................................0.42
[ T015: x := F_D ]..............................................0.17
[ T016: x := o:Args ]...........................................0.39
[ T017: x := o[2] ].............................................0.25
[ T018: round( i / 1000, 2 ) ]..................................0.47
[ T019: str( i / 1000 ) ].......................................1.72
[ T020: val( s ) ]..............................................0.59
[ T021: val( a [ i % 16 + 1 ] ) ]...............................1.03
[ T022: dtos( d - i % 10000 ) ].................................1.83
[ T023: eval( { || i % 16 } ) ].................................1.50
[ T024: eval( bc := { || i % 16 } ) ]...........................0.55
[ T025: eval( { |x| x % 16 }, i ) ].............................1.00
[ T026: eval( bc := { |x| x % 16 }, i ) ].......................0.53
[ T027: eval( { |x| f1( x ) }, i ) ]............................1.13
[ T028: eval( bc := { |x| f1( x ) }, i ) ]......................0.66
[ T029: eval( bc := &("{ |x| f1( x ) }"), i ) ].................0.69
[ T030: x := &( "f1(" + str(i) + ")" ) ]........................8.33
[ T031: bc := &( "{|x|f1(x)}" ), eval( bc, i ) ]...............10.95
[ T032: x := valtype( x ) +  valtype( i ) ].....................1.09
[ T033: x := strzero( i % 100, 2 ) $ a[ i % 16 + 1 ] ]..........1.91
[ T034: x := a[ i % 16 + 1 ] == s ].............................0.80
[ T035: x := a[ i % 16 + 1 ] = s ]..............................0.84
[ T036: x := a[ i % 16 + 1 ] >= s ].............................0.83
[ T037: x := a[ i % 16 + 1 ] <= s ].............................0.84
[ T038: x := a[ i % 16 + 1 ] < s ]..............................0.83
[ T039: x := a[ i % 16 + 1 ] > s ]..............................0.83
[ T040: ascan( a, i % 16 ) ]....................................0.69
[ T041: ascan( a, { |x| x == i % 16 } ) ].......................7.23
[ T042: iif( i%1000==0, a:={}, ) , aadd(a,{i,1,.T.,s,s2,a2 ]....2.75
[ T043: x := a ]................................................0.16
[ T044: x := {} ]...............................................0.61
[ T045: f0() ]..................................................0.13
[ T046: f1( i ) ]...............................................0.22
[ T047: f2( c[1...8] ) ]........................................0.30
[ T048: f2( c[1...40000] ) ]....................................0.31
[ T049: f2( @c[1...40000] ) ]...................................0.30
[ T050: f2( @c[1...40000] ), c2 := c ]..........................0.34
[ T051: f3( a, a2, s, i, s2, bc, i, n, x ) ]....................1.00
[ T052: f2( a ) ]...............................................0.30
[ T053: x := f4() ].............................................1.63
[ T054: x := f5() ].............................................0.77
[ T055: x := space(16) ]........................................0.64
[ T056: f_prv( c ) ]............................................1.39
====================================================================
[ total application time: ]....................................64.47
[ total real time: ]...........................................64.58
E o Harbour compilador com MSVC também em Multi Thread.

Código: Selecionar todos

03/19/09 13:43:12 Windows XP 5.1.2600 Service Pack 3
Harbour 1.1.0dev (Rev. 10643) (MT) Microsoft Visual C++ 15.0.26569 (32-bit)
THREADS: 0
N_LOOPS: 1000000
[ T000: empty loop overhead ]...................................0.05
====================================================================
[ T001: x := L_C ]..............................................0.13
[ T002: x := L_N ]..............................................0.03
[ T003: x := L_D ]..............................................0.02
[ T004: x := S_C ]..............................................0.13
[ T005: x := S_N ]..............................................0.03
[ T006: x := S_D ]..............................................0.03
[ T007: x := M->M_C ]...........................................0.17
[ T008: x := M->M_N ]...........................................0.05
[ T009: x := M->M_D ]...........................................0.05
[ T010: x := M->P_C ]...........................................0.16
[ T011: x := M->P_N ]...........................................0.06
[ T012: x := M->P_D ]...........................................0.05
[ T013: x := F_C ]..............................................0.47
[ T014: x := F_N ]..............................................0.31
[ T015: x := F_D ]..............................................0.16
[ T016: x := o:Args ]...........................................0.28
[ T017: x := o[2] ].............................................0.20
[ T018: round( i / 1000, 2 ) ]..................................0.28
[ T019: str( i / 1000 ) ].......................................0.88
[ T020: val( s ) ]..............................................0.44
[ T021: val( a [ i % 16 + 1 ] ) ]...............................0.75
[ T022: dtos( d - i % 10000 ) ].................................0.86
[ T023: eval( { || i % 16 } ) ].................................1.36
[ T024: eval( bc := { || i % 16 } ) ]...........................0.47
[ T025: eval( { |x| x % 16 }, i ) ].............................0.88
[ T026: eval( bc := { |x| x % 16 }, i ) ].......................0.47
[ T027: eval( { |x| f1( x ) }, i ) ]............................0.92
[ T028: eval( bc := { |x| f1( x ) }, i ) ]......................0.48
[ T029: eval( bc := &("{ |x| f1( x ) }"), i ) ].................0.52
[ T030: x := &( "f1(" + str(i) + ")" ) ]........................6.30
[ T031: bc := &( "{|x|f1(x)}" ), eval( bc, i ) ]................8.53
[ T032: x := valtype( x ) +  valtype( i ) ].....................0.78
[ T033: x := strzero( i % 100, 2 ) $ a[ i % 16 + 1 ] ]..........1.33
[ T034: x := a[ i % 16 + 1 ] == s ].............................0.61
[ T035: x := a[ i % 16 + 1 ] = s ]..............................0.66
[ T036: x := a[ i % 16 + 1 ] >= s ].............................0.64
[ T037: x := a[ i % 16 + 1 ] <= s ].............................0.66
[ T038: x := a[ i % 16 + 1 ] < s ]..............................0.64
[ T039: x := a[ i % 16 + 1 ] > s ]..............................0.66
[ T040: ascan( a, i % 16 ) ]....................................0.50
[ T041: ascan( a, { |x| x == i % 16 } ) ].......................6.00
[ T042: iif( i%1000==0, a:={}, ) , aadd(a,{i,1,.T.,s,s2,a2 ]....2.28
[ T043: x := a ]................................................0.14
[ T044: x := {} ]...............................................0.58
[ T045: f0() ]..................................................0.09
[ T046: f1( i ) ]...............................................0.13
[ T047: f2( c[1...8] ) ]........................................0.23
[ T048: f2( c[1...40000] ) ]....................................0.25
[ T049: f2( @c[1...40000] ) ]...................................0.23
[ T050: f2( @c[1...40000] ), c2 := c ]..........................0.28
[ T051: f3( a, a2, s, i, s2, bc, i, n, x ) ]....................0.80
[ T052: f2( a ) ]...............................................0.25
[ T053: x := f4() ].............................................1.47
[ T054: x := f5() ].............................................0.61
[ T055: x := space(16) ]........................................0.52
[ T056: f_prv( c ) ]............................................1.14
====================================================================
[ total application time: ]....................................49.66
[ total real time: ]...........................................49.75
Agora o Fonte.

Código: Selecionar todos

/*
 * $Id: speedtst.prg 10647 2009-03-18 18:54:17Z druzus $
 */

/*
 * Harbour Project source code:
 *    HVM speed test program
 *
 * Copyright 2008 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
 * www - http://www.harbour-project.org
 *
 */

#define N_TESTS 56
#define N_LOOPS 1000000
#define ARR_LEN 16

#ifndef __HARBOUR__
   #ifndef __XPP__
      #ifndef __CLIP__
        #define __CLIPPER__
      #endif
   #endif
#endif


#ifdef __CLIPPER__
   /* Clipper does not support multithreading */
   #ifndef __ST__
      #define __ST__
   #endif
#endif

#ifdef __XPP__
   #define __NO_OBJ_ARRAY__
   /* xBase++ version for MT performance testing is not ready yet */
   #ifndef __ST__
      #define __ST__
   #endif
#endif

#ifdef __CLIP__
   #define __NO_OBJ_ARRAY__
   /* CLIP version for MT performance testing is not ready yet */
   #ifndef __ST__
      #define __ST__
   #endif
#endif

#ifdef __XHARBOUR__
   /* By default build xHarbour binaries without MT support
    * xHarbour needs separated version for MT and ST mode
    * because standard MT functions are not available in
    * ST libraries.
    */
   #ifndef __ST__
      #ifndef __MT__
         #ifndef MT
            #ifndef HB_THREAD_SUPPORT
               #define __ST__
            #endif
         #endif
      #endif
   #endif
#endif

/* by default create MT version */
#ifndef __MT__
   #ifndef __ST__
      #define __MT__
   #endif
#endif


#command ? => outstd(EOL)
#command ? <xx,...> => outstd(EOL);outstd(<xx>)
#command ?? <xx,...> => outstd(<xx>)

#ifdef __HARBOUR__
   #ifndef EOL
      #define EOL hb_OSNewLine()
   #endif
#else
   #ifndef __CLIP__
      #xtranslate secondsCPU() => seconds()
      #ifndef EOL
         #define EOL chr(10)
      #endif
   #else
      #define EOL chr(13)+chr(10)
   #endif
#endif

#xcommand TEST <testfunc>           ;
          [ WITH <locals,...> ]     ;
          [ STATIC <statics,...> ]  ;
          [ FIELD  <fields,...> ]   ;
          [ MEMVAR <memvars,...> ]  ;
          [ PRIVATE <privates,...> ];
          [ PUBLIC <publics,...> ]  ;
          [ INIT <init> ]           ;
          [ EXIT <exit> ]           ;
          [ INFO <info> ]           ;
          CODE [ <testExp,...> ] => ;
   func <testfunc> ;                ;
      local time, i:=nil, x:=nil ;  ;
      [ local <locals> ; ]          ;
      [ static <statics> ; ]        ;
      [ field <fields> ; ]          ;
      [ memvar <memvars> ; ]        ;
      [ private <privates> ; ]      ;
      [ public <publics> ; ]        ;
      [ <init> ; ]                  ;
      time := secondscpu() ;        ;
      for i:=1 to N_LOOPS ;         ;
         [ ( <testExp> ) ; ]        ;
      next ;                        ;
      time := secondscpu() - time ; ;
      [ <exit> ; ]                  ;
   return { procname() + ": " + iif( <.info.>, <(info)>, #<testExp> ), time }

#ifdef __HARBOUR__
proc main( ... )
   local aParams := hb_aparams()
#else
proc main( _p01, _p02, _p03, _p04, _p05, _p06, _p07, _p08, _p09, _p10, ;
           _p11, _p12, _p13, _p14, _p15, _p16, _p17, _p18, _p19, _p20 )
   local aParams := ;
      asize( { _p01, _p02, _p03, _p04, _p05, _p06, _p07, _p08, _p09, _p10, ;
               _p11, _p12, _p13, _p14, _p15, _p16, _p17, _p18, _p19, _p20 }, ;
             min( pCount(), 20 ) )
#endif
   local nMT, cExclude, lScale, cParam, cMemTests, lSyntax, i, j

   lSyntax := lScale := .f.
   cMemTests := "030 031 023 025 027 041 042 044 053 054 019 022 032 033 055 056 "
   cExclude := ""
   nMT := 0
   for j := 1 to len( aParams )
      cParam := lower( aParams[ j ] )
      if cParam = "--thread"
         if substr( cParam, 9, 1 ) == "="
            if isdigit( substr( cParam, 10, 1 ) )
               nMT := val( substr( cParam, 10 ) )
            elseif substr( cParam, 10 ) == "all"
               nMT := -1
            else
               lSyntax = .t.
            endif
         elseif empty( substr( cParam, 9 ) )
            nMT := -1
         else
            lSyntax = .t.
         endif
      elseif cParam = "--exclude="
         if substr( cParam, 11 ) == "mem"
            cExclude += cMemTests
         else
            cExclude += strtran( strtran( strtran( substr( cParam, 11 ), ;
                        ".", " " ), ".", " " ), "/", " " ) + " "
         endif
      elseif cParam = "--only="
         cExclude := ""
         if substr( cParam, 8 ) == "mem"
            cParam := cMemTests
         endif
         for i := 1 to N_TESTS
            if !strzero( i, 3 ) $ cParam
               cExclude += strzero( i, 3 ) + " "
            endif
         next
      elseif cParam = "--scale"
         lScale := .t.
      else
         lSyntax = .t.
      endif
      if lSyntax
         ? "Unknown option:", cParam
         ? "syntax: speedtst [--thread[=<num>]] [--only=<test(s)>] [--exclude=<test(s)>]"
         ?
         return
      endif
   next
   test( nMT, cExclude, lScale )
return


/*** TESTS ***/

TEST t000 INFO "empty loop overhead" CODE

TEST t001 WITH L_C:=dtos(date()) CODE x := L_C

TEST t002 WITH L_N:=112345.67    CODE x := L_N

TEST t003 WITH L_D:=date()       CODE x := L_D

TEST t004 STATIC s_once := NIL, S_C ;
          INIT hb_threadOnce( @s_once, {|| S_C := dtos( date() ) } ) ;
          CODE x := S_C

TEST t005 STATIC s_once := NIL, S_N ;
          INIT hb_threadOnce( @s_once, {|| S_N := 112345.67 } ) ;
          CODE x := S_N

TEST t006 STATIC s_once := NIL, S_D ;
          INIT hb_threadOnce( @s_once, {|| S_D := date() } ) ;
          CODE x := S_D

TEST t007 MEMVAR M_C ;
          PRIVATE M_C := dtos( date() ) ;
          CODE x := M->M_C

TEST t008 MEMVAR M_N ;
          PRIVATE M_N := 112345.67 ;
          CODE x := M->M_N

TEST t009 MEMVAR M_D ;
          PRIVATE M_D := date() ;
          CODE x := M->M_D

TEST t010 STATIC s_once := NIL ;
          MEMVAR P_C ;
          PUBLIC P_C ;
          INIT hb_threadOnce( @s_once, {|| M->P_C := dtos( date() ) } ) ;
          CODE x := M->P_C

TEST t011 STATIC s_once := NIL ;
          MEMVAR P_N ;
          PUBLIC P_N ;
          INIT hb_threadOnce( @s_once, {|| M->P_N := 112345.67 } ) ;
          CODE x := M->P_N

TEST t012 STATIC s_once := NIL ;
          MEMVAR P_D ;
          PUBLIC P_D ;
          INIT hb_threadOnce( @s_once, {|| M->P_D := date() } ) ;
          CODE x := M->P_D

TEST t013 FIELD  F_C ;
          INIT use_dbsh() EXIT close_db() ;
          CODE x := F_C

TEST t014 FIELD F_N ;
          INIT use_dbsh() EXIT close_db() ;
          CODE x := F_N

TEST t015 FIELD F_D ;
          INIT use_dbsh() EXIT close_db() ;
          CODE x := F_D

TEST t016 WITH o := errorNew() CODE x := o:Args

TEST t017 WITH o := errorArray() CODE x := o[2]

TEST t018 CODE round( i / 1000, 2 )

TEST t019 CODE str( i / 1000 )

TEST t020 WITH s := stuff( dtos( date() ), 7, 0, "." ) CODE val( s )

TEST t021 WITH a := afill( array( ARR_LEN ), ;
                           stuff( dtos( date() ), 7, 0, "." ) ) ;
          CODE val( a [ i % ARR_LEN + 1 ] )

TEST t022 WITH d := date() CODE dtos( d - i % 10000 )

TEST t023 CODE eval( { || i % ARR_LEN } )

TEST t024 WITH bc := { || i % ARR_LEN } ;
          INFO eval( bc := { || i % ARR_LEN } ) ;
          CODE eval( bc )

TEST t025 CODE eval( { |x| x % ARR_LEN }, i )

TEST t026 WITH bc := { |x| x % ARR_LEN } ;
          INFO eval( bc := { |x| x % ARR_LEN }, i ) ;
          CODE eval( bc, i )

TEST t027 CODE eval( { |x| f1( x ) }, i )

TEST t028 WITH bc := { |x| f1( x ) } ;
          INFO eval( bc := { |x| f1( x ) }, i ) ;
          CODE eval( bc, i )

TEST t029 WITH bc := mkBlock( "{ |x| f1( x ) }" ) ;
          INFO eval( bc := &("{ |x| f1( x ) }"), i ) ;
          CODE eval( bc, i )

TEST t030 CODE x := &( 'f1(' + str(i) + ')' )

TEST t031 WITH bc CODE bc := &( '{|x|f1(x)}' ), eval( bc, i )

TEST t032 CODE x := valtype( x ) +  valtype( i )

TEST t033 WITH a := afill( array( ARR_LEN ), ;
                           stuff( dtos( date() ), 7, 0, "." ) ) ;
          CODE x := strzero( i % 100, 2 ) $ a[ i % ARR_LEN + 1 ]

TEST t034 WITH a := array( ARR_LEN ), s := dtos( date() ) ;
          INIT aeval( a, { |x,i| a[i] := left( s + s, i ), x } ) ;
          CODE x := a[ i % ARR_LEN + 1 ] == s

TEST t035 WITH a := array( ARR_LEN ), s := dtos( date() ) ;
          INIT aeval( a, { |x,i| a[i] := left( s + s, i ), x } ) ;
          CODE x := a[ i % ARR_LEN + 1 ] = s

TEST t036 WITH a := array( ARR_LEN ), s := dtos( date() ) ;
          INIT aeval( a, { |x,i| a[i] := left( s + s, i ), x } ) ;
          CODE x := a[ i % ARR_LEN + 1 ] >= s

TEST t037 WITH a := array( ARR_LEN ), s := dtos( date() ) ;
          INIT aeval( a, { |x,i| a[i] := left( s + s, i ), x } ) ;
          CODE x := a[ i % ARR_LEN + 1 ] <= s

TEST t038 WITH a := array( ARR_LEN ), s := dtos( date() ) ;
          INIT aeval( a, { |x,i| a[i] := left( s + s, i ), x } ) ;
          CODE x := a[ i % ARR_LEN + 1 ] < s

TEST t039 WITH a := array( ARR_LEN ), s := dtos( date() ) ;
          INIT aeval( a, { |x,i| a[i] := left( s + s, i ), x } ) ;
          CODE x := a[ i % ARR_LEN + 1 ] > s

TEST t040 WITH a := array( ARR_LEN ) ;
          INIT aeval( a, { |x,i| a[i] := i, x } ) ;
          CODE ascan( a, i % ARR_LEN )

TEST t041 WITH a := array( ARR_LEN ) ;
          INIT aeval( a, { |x,i| a[i] := i, x } ) ;
          CODE ascan( a, { |x| x == i % ARR_LEN } )

TEST t042 WITH a := {}, a2 := { 1, 2, 3 }, bc := { |x| f1(x) }, ;
               s := dtos( date() ), s2 := "static text" ;
          CODE iif( i%1000==0, a:={}, ) , aadd(a,{i,1,.t.,s,s2,a2,bc})

TEST t043 WITH a := {} CODE x := a

TEST t044 CODE x := {}

TEST t045 CODE f0()

TEST t046 CODE f1( i )

TEST t047 WITH c := dtos( date() ) ;
          INFO f2( c[1...8] ) ;
          CODE f2( c )

TEST t048 WITH c := repl( dtos( date() ), 5000 ) ;
          INFO f2( c[1...40000] ) ;
          CODE f2( c )

TEST t049 WITH c := repl( dtos( date() ), 5000 ) ;
          INFO f2( @c[1...40000] ) ;
          CODE f2( c )

TEST t050 WITH c := repl( dtos( date() ),5000 ), c2 ;
          INFO "f2( @c[1...40000] ), c2 := c" ;
          CODE f2( @c ), c2 := c

TEST t051 WITH a := {}, a2 := { 1, 2, 3 }, bc := { |x| f1(x) }, ;
               s := dtos( date() ), s2 := "static text", n := 1.23 ;
          CODE f3( a, a2, s, i, s2, bc, i, n, x )

TEST t052 WITH a := { 1, 2, 3 } CODE f2( a )

TEST t053 CODE x := f4()

TEST t054 CODE x := f5()

TEST t055 CODE x := space(16)

TEST t056 WITH c := dtos( date() ) CODE f_prv( c )

/*** end of tests ***/


#ifdef __MT__

function thTest( mtxJobs, aResults )
   local xJob
   while .T.
      hb_mutexSubscribe( mtxJobs,, @xJob )
      if xJob == NIL
         exit
      endif
      aResults[ xJob ] := &( "t" + strzero( xJob, 3 ) )()
   enddo
return nil

function thTestScale( mtxJobs, mtxResults )
   local xJob
   while .T.
      hb_mutexSubscribe( mtxJobs,, @xJob )
      if xJob == NIL
         exit
      endif
      hb_mutexNotify( mtxResults, &( "t" + strzero( xJob, 3 ) )() )
   enddo
return nil

#endif


proc test( nMT, cExclude, lScale )
local nLoopOverHead, nTimes, nSeconds, cNum, aThreads, aResults, ;
      mtxJobs, mtxResults, nTimeST, nTimeMT, nTimeTotST, nTimeTotMT, ;
      cTest, x, i, j

create_db()

#ifdef __HARBOUR__
   #include "hbmemory.ch"
      if MEMORY( HB_MEM_USEDMAX ) != 0
      ? "Warning !!! Memory statistic enabled."
      ?
   endif
#endif

//? "Startup loop to increase CPU clock..."
//x := seconds() + 5; while x > seconds(); enddo

#ifdef __MT__
if !hb_mtvm()
#else
if .t.
#endif
   if lScale
      ? "scale test available only in MULTI THREAD mode"
      ?
      return
   endif
   if nMT != 0
      ? "SINGLE THREAD mode, number of threads set to 0"
      nMT := 0
   endif
endif
? date(), time(), os()
? version() + iif( hb_mtvm(), " (MT)" + iif( nMT != 0, "+", "" ), "" ), ""
#ifdef __HARBOUR__
   ?? hb_compiler()
#endif

if lScale .and. nMT < 1
   nMT := 1
endif

? "THREADS:", iif( nMT < 0, "all->" + ltrim( str( N_TESTS ) ), ltrim( str( nMT ) ) )
? "N_LOOPS:", ltrim( str( N_LOOPS ) )
if !empty( cExclude )
   ? "excluded tests:", cExclude
endif

x :=t000()
nLoopOverHead := x[2]

if lScale
   ? space(56) + "1 th." + str(nMT,3) + " th.  factor"
   ? replicate("=",76)
else
   ? dsp_result( x, 0 )
   ? replicate("=",68)
endif

nSeconds := seconds()
nTimes := secondsCPU()

nTimeTotST := nTimeTotMT := 0

#ifdef __MT__
   if lScale
      mtxJobs := hb_mutexCreate()
      mtxResults := hb_mutexCreate()
      for i:=1 to nMT
         hb_threadStart( "thTestScale", mtxJobs, mtxResults )
      next
      for i:=1 to N_TESTS
         cTest := strzero( i, 3 )
         if !cTest $ cExclude

            /* linear execution */
            nTimeST := seconds()
            for j:=1 to nMT
               hb_mutexNotify( mtxJobs, i )
               hb_mutexSubscribe( mtxResults,, @x )
               cTest := x[1]
            next
            nTimeST := seconds() - nTimeST
            nTimeTotST += nTimeST

            /* simultaneous execution */
            nTimeMT := seconds()
            for j:=1 to nMT
               hb_mutexNotify( mtxJobs, i )
            next
            for j:=1 to nMT
               hb_mutexSubscribe( mtxResults,, @x )
               cTest := x[1]
            next
            nTimeMT := seconds() - nTimeMT
            nTimeTotMT += nTimeMT

            ? dsp_scaleResult( cTest, nTimeST, nTimeMT, nMT, nLoopOverHead )
         endif

      next
      for i:=1 to nMT
         hb_mutexNotify( mtxJobs, NIL )
      next
      hb_threadWaitForAll()
   elseif nMT < 0
      aThreads := array( N_TESTS )
      for i:=1 to N_TESTS
         cNum := strzero( i, 3 )
         if !cNum $ cExclude
            aThreads[ i ] := hb_threadStart( "t" + cNum )
         endif
      next
      for i:=1 to N_TESTS
         if aThreads[ i ] != NIL .and. hb_threadJoin( aThreads[ i ], @x )
            ? dsp_result( x, nLoopOverHead )
         endif
      next
   elseif nMT > 0
      aResults := array( N_TESTS )
      mtxJobs := hb_mutexCreate()
      for i:=1 to nMT
         hb_threadStart( "thTest", mtxJobs, aResults )
      next
      for i:=1 to N_TESTS
         if !strzero( i, 3 ) $ cExclude
            hb_mutexNotify( mtxJobs, i )
         endif
      next
      for i:=1 to nMT
         hb_mutexNotify( mtxJobs, NIL )
      next
      hb_threadWaitForAll()
      for i:=1 to N_TESTS
         if aResults[ i ] != NIL
            ? dsp_result( aResults[ i ], nLoopOverHead )
         endif
      next
      mtxJobs := NIL
   else
      for i:=1 to N_TESTS
         cNum := strzero( i, 3 )
         if !cNum $ cExclude
            ? dsp_result( &( "t" + cNum )(), nLoopOverHead )
         endif
      next
   endif
#else
   for i:=1 to N_TESTS
      cNum := strzero( i, 3 )
      if !cNum $ cExclude
         ? dsp_result( &( "t" + cNum )(), nLoopOverHead )
      endif
   next
#endif

nTimes := secondsCPU() - nTimes
nSeconds := seconds() - nSeconds

if lScale
   ? replicate("=",76)
   ? dsp_scaleResult( "  TOTAL  ", nTimeTotST, nTimeTotMT, nMT, 0 )
   ? replicate("=",76)
else
   ? replicate("=",68)
endif
? dsp_result( { "total application time:", nTimes }, 0)
? dsp_result( { "total real time:", nSeconds }, 0 )
?

remove_db()
return

function f0()
return nil

function f1(x)
return x

function f2(x)
return nil

function f3(a,b,c,d,e,f,g,h,i)
return nil

function f4()
return space(4000)

function f5()
return space(5)

function f_prv(x)
   memvar PRV_C
   private PRV_C := x
return nil

/*
function f_pub(x)
   memvar PUB_C
   public PUB_C := x
return nil

function f_stat(x)
   static STAT_C
   STAT_C := x
return nil
*/

static function mkBlock(x)
return &x

static function errorArray()
#ifdef __NO_OBJ_ARRAY__
   return array(16)
#else
   return errorNew()
#endif

static func dsp_result( aResult, nLoopOverHead )
   return padr( "[ " + left( aResult[1], 56 ) + " ]", 60, "." ) + ;
          strtran( str( max( aResult[2] - nLoopOverHead, 0 ), 8, 2 ), " ", "." )

static func dsp_scaleResult( cTest, nTimeST, nTimeMT, nMT, nLoopOverHead )
   if .f.
      nTimeST := max( 0, nTimeST - nMT * nLoopOverHead )
      nTimeMT := max( 0, nTimeMT - nMT * nLoopOverHead )
   endif
   return padr( "[ " + left( cTest, 50 ) + " ]", 54, "_" ) + ;
          str( nTimeST, 6, 2 ) + " " + str( nTimeMT, 6, 2 ) + " ->" + ;
          str( nTimeST / nTimeMT, 6, 2 )


#define TMP_FILE "_tst_tmp.dbf"
static proc create_db()
   remove_db()
   dbcreate( TMP_FILE, { {"F_C", "C", 10, 0},;
                         {"F_N", "N", 10, 2},;
                         {"F_D", "D",  8, 0} } )
   use TMP_FILE exclusive
   dbappend()
   replace F_C with dtos(date())
   replace F_N with 112345.67
   replace F_D with date()
   close
return

static proc remove_db()
   ferase( TMP_FILE )
return

static proc close_db()
   close
return

static proc use_dbsh()
   use TMP_FILE shared
return


#ifdef __CLIPPER__
   function hb_mtvm()
   return .f.                 /* Clipper does not support MT */
#endif
#ifdef __CLIP__
   function hb_mtvm()
   return .t.                 /* CLIP always uses VM with MT support */
#endif
#ifdef __XPP__
   function hb_mtvm()
   return .t.                 /* xBase++ always uses VM with MT support */
#endif
#ifdef __XHARBOUR__
   function hb_mtvm()
   return hb_multiThread()    /* check for MT support in xHarbour VM */
#endif


#ifndef __MT__

   /* trivial single thread version of once execution */
   function hb_threadOnce( xOnceControl, bAction )
      local lFirstCall := .f.
      if xOnceControl == NIL
         if bAction != NIL
            eval( bAction )
         endif
         xOnceControl := .t.
         lFirstCall := .t.
      endif
   return lFirstCall

#else

   /* Add support for MT functions for used compiler
    */

#ifdef __XHARBOUR__

   /* do not expect that this code will work with xHarbour.
    * xHarbour has many race conditions which are exploited quite fast
    * on real multi CPU machines so it crashes in different places :-(
    * probably this code should be forwared to xHarbour developers as
    * some type of MT test
    */

   /* this define is only to test if emulation function works
    * without running real test which causes that xHarbour crashes
    */
   //#define _DUMY_XHB_TEST_


   function hb_mutexSubscribe( mtx, nTimeOut, xSubscribed )
      local lSubscribed
      if valtype( nTimeOut ) == "N"
         nTimeOut := round( nTimeOut * 1000, 0 )
         xSubscribed := Subscribe( mtx, nTimeOut, @lSubscribed )
      else
         xSubscribed := Subscribe( mtx )
         lSubscribed := .t.
      endif
   return lSubscribed

   function hb_mutexNotify( mtx, xValue )
      Notify( mtx, xValue )
   return nil

   /* in xHarbour there is race condition in JoinThread() which
    * fails if thread end before we call it so we cannot use it :-(
    * this code tries to simulate it and also add support for thread
    * return value
    */

   function hb_threadStart( ... )
      local thId
      thId := StartThread( @threadFirstFunc(), hb_aParams() )
      /* Just like in JoinThread() the same race condition exists in
       * GetThreadId() so we will use HVM thread numbers internally
       */
#ifdef _DUMY_XHB_TEST_
   return val( substr( hb_aParams()[1], 2 ) )
#else
   return GetThreadId( thId )
#endif

   function hb_threadJoin( thId, xResult )
      xResult := results( thId )
   return .t.

   static function threadFirstFunc( aParams )
      local xResult
#ifdef _DUMY_XHB_TEST_
      xResult := { "skipped test " + aParams[1], val( substr( aParams[1], 2 ) ) + 0.99 }
      results( val( substr( aParams[1], 2 ) ), xResult )
#else
      xResult := hb_execFromArray( aParams )
      results( GetThreadId(), xResult )
#endif
   return nil

   static function results( nThread, xResult )
      static s_aResults
      static s_mutex
      if s_aResults == nil
         s_aResults := HSetAutoAdd( hash(), .t. )
         s_mutex := hb_mutexCreate()
      endif
      if pcount() < 2
         while ! nThread $ s_aResults
            Subscribe( s_mutex, 1000 )
         enddo
         xResult := s_aResults[ nThread ]
      else
         s_aResults[ nThread ] := xResult
         /* We cannot use NotifyAll() here because it will create
          * race condition. In this program only one thread join
          * results so we can use simple Notify() as workaround
          */
         //NotifyAll( s_mutex )
         Notify( s_mutex )
      endif
   return xResult

   function hb_threadWaitForAll()
      WaitForThreads()
   return nil

   function hb_threadOnce( xOnceControl, bAction )
      static s_mutex
      local lFirstCall := .f.
      if s_mutex == NIL
         s_mutex := hb_mutexCreate()
      endif
      if xOnceControl == NIL
         hb_mutexLock( s_mutex )
         if xOnceControl == NIL
            if bAction != NIL
               eval( bAction )
            endif
            xOnceControl := .t.
            lFirstCall := .t.
         endif
         hb_mutexUnlock( s_mutex )
      endif
   return lFirstCall

   init proc once_init()
      /* set workareas local to thread */
      set workarea private
      /* initialize mutex in hb_trheadDoOnce() */
      hb_threadOnce()
      /* initialize error object to reduce possible crashes when two
       * threads will try to create new error class simultaneously.
       * xHarbour does not have any protection against such situation
       */
      errorNew()
   return

#endif /* __XHARBOUR__ */


/*
   function hb_threadStart( cFunc, xPar1, xPar2, xPar3 )
   return nil

   function hb_threadJoin( thId, xResult )
   return nil

   function hb_mutexCreate()
   return nil

   function hb_mutexSubscribe()
   return nil
   function hb_mutexLock()
   return nil
   function hb_mutexUnlock()
   return nil
   function hb_mutexNotify()
   return nil
   function hb_threadWaitForAll()
   return nil
   function hb_mtvm()
   return .f.
*/

#endif
Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7928
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Re: Harbour Teste de Velocidade.

Mensagem por Itamar M. Lins Jr. »

Código: Selecionar todos

Agora, pra botar software no cliente, eu JAMAIS usaria o GCC...
Uma pergunta. Qual é a versão do BCC e GCC que estas usando ?
Sei que voce não usará GCC em seus cliente mas sua colocação está limitada ao ambiente Windows, correto ?

Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7928
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Re: Harbour Teste de Velocidade.

Mensagem por Itamar M. Lins Jr. »

Finalizando a análise: eu não produzo carros de corrida. Produzo software. Velocidade máxima, cuja diferença é mínima em relação ao que tenho, não me garante boas vendas. O que garante o dinheiro entrando é a satisfação dos clientes quanto aos recursos que ofereço no meu software. Por isso nunca dei a menor importância pra esse tipo de teste. Se eu tiver confiabilidade, já me considero plenamente satisfeito.

Se tivesse que dar um conselho aos colegas, eu diria: desencanem dessa história de velocidade. Isso não é tão importante quanto parece.
Creio que o objetivo do teste não seja esse, mas sim mostrar a performance do Harbour usando esses compiladores, serve tambem para mostrar a versatilidade do Harbour em poder ser usado por em todos esses compiladores e comparar o Harbour frente ao xHarbour e ao xBase++ que é considerado por muitos um excelente produto.
E frente ao clipper, como já havia dito em outras oportunidades, na minha maneira de pensar, não faz mas sentido continuar usando-o, a não ser temporáriamente enquanto o interessado não mude para "n" opções.

Saudações,
Itamar M. Lins Jr.
Editado pela última vez por Itamar M. Lins Jr. em 22 Mar 2009 09:53, em um total de 1 vez.
Saudações,
Itamar M. Lins Jr.
Avatar do usuário
Maligno
Membro Master
Membro Master
Mensagens: 6398
Registrado em: 06 Jul 2004 01:40
Localização: Londrina/PR

Re: Harbour Teste de Velocidade.

Mensagem por Maligno »

Itamar M. Lins Jr. escreveu:Uma pergunta. Qual é a versão do BCC e GCC que estas usando ?
A versão do BCC que eu uso (muito pouco) em linha de comando é a o do "FreeCommandLineTools", a 5.5.1. A que uso direto no trabalho é a do C++ Builder 2006, que é a 5.82. E a versão do GCC é a 3.4.2.
[]'s
Maligno
---
Não respondo questões técnicas através de MP ou eMail. Não insista.
As dúvidas devem ser postadas no fórum. Desta forma, todos poderão
se beneficiar das respostas.

---
Se um dia precisar de uma transfusão de sangue você perceberá como
é importante a figura do doador. Procure o hemocentro de sua cidade e
se informe sobre a doação de sangue, plaquetas e medula óssea. Doe!
Avatar do usuário
Maligno
Membro Master
Membro Master
Mensagens: 6398
Registrado em: 06 Jul 2004 01:40
Localização: Londrina/PR

Re: Harbour Teste de Velocidade.

Mensagem por Maligno »

Itamar M. Lins Jr. escreveu:Creio que o objetivo do teste não seja esse, mas sim mostrar a performance do Harbour usando esses compiladores, serve tambem para mostrar a versatilidade do Harbour em poder ser usado por em todos esses compiladores e comparar o Harbour frente ao xHarbour e ao xBase++ que é considerado por muitos um excelente produto.
Sim, até entendo que esse seja o objetivo, mas pode reparar que já teve gente perguntando como trocar de compilador C. Ou seja, testes desse tipo sempre influenciam alguém, pois o que é mais rápido sempre se torna mais atraente. Daí o motivo da minha observação.
[]'s
Maligno
---
Não respondo questões técnicas através de MP ou eMail. Não insista.
As dúvidas devem ser postadas no fórum. Desta forma, todos poderão
se beneficiar das respostas.

---
Se um dia precisar de uma transfusão de sangue você perceberá como
é importante a figura do doador. Procure o hemocentro de sua cidade e
se informe sobre a doação de sangue, plaquetas e medula óssea. Doe!
Avatar do usuário
vailton
Colaborador
Colaborador
Mensagens: 390
Registrado em: 17 Nov 2005 19:08
Localização: Brasil
Contato:

Re: Harbour Teste de Velocidade.

Mensagem por vailton »

Maligno escreveu:A versão do BCC que eu uso (muito pouco) em linha de comando é a o do "FreeCommandLineTools", a 5.5.1. A que uso direto no trabalho é a do C++ Builder 2006, que é a 5.82. E a versão do GCC é a 3.4.2.
A versão 5.5.1 que é comumente usada por muitos com Harbour/xHarbour e infelizmente comtém vários bugs. De fato ela é rápida, mas possui informações faltantes e incompletas nos arquivos .H (até porque estão desatualizados à 9 anos), o resource compiler dele não suporta imagens com muitas cores (32bit ou mais senão me engano) o linker.exe possui erros ao lidas com .RC com multiplos ícones e mais alguns problemas que estavam listados no site da Borland mas infelizmente não achei o link para mostrar.

Eu cheguei a usar muito ele e embora tenha estes e outros problemas, na época trabalhou bem.
Vailton Renato
"No dia mais claro, na noite mais escura... o bug sucumbirá ante a minha presença"

E-mail/MSN: contato@vailton.com.br
Skype: vailtom
Avatar do usuário
Maligno
Membro Master
Membro Master
Mensagens: 6398
Registrado em: 06 Jul 2004 01:40
Localização: Londrina/PR

Re: Harbour Teste de Velocidade.

Mensagem por Maligno »

Essa versão nunca me deu qualquer problema. Numa certa época usei muito. Hoje só pra alguns testes. Realmente não tenho do que reclamar. Ou seja: na minha experiência pessoal, essa versão foi e ainda é confiável, para o pouco uso de hoje. Mas mesmo uma boa versão de compilador pode ter alguns bugs mesmo. Deve ter alguma coisa no QC (Qality Central) da Codegear. Eu mesmo achei um bug no TLIB do RAD2009. E parei de usar por isso. Ainda não resolveram. :(
[]'s
Maligno
---
Não respondo questões técnicas através de MP ou eMail. Não insista.
As dúvidas devem ser postadas no fórum. Desta forma, todos poderão
se beneficiar das respostas.

---
Se um dia precisar de uma transfusão de sangue você perceberá como
é importante a figura do doador. Procure o hemocentro de sua cidade e
se informe sobre a doação de sangue, plaquetas e medula óssea. Doe!
Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7928
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Re: Harbour Teste de Velocidade.

Mensagem por Itamar M. Lins Jr. »

Não sei porque eu, mas...
Depois dessas informações todas, ainda pergunta pq você?
:-Y

Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
rodrmigu
Usuário Nível 3
Usuário Nível 3
Mensagens: 150
Registrado em: 27 Nov 2007 15:13
Localização: Indaiatuba SP

Re: Harbour Teste de Velocidade.

Mensagem por rodrmigu »

Bom,

Por experiência própria, tenho usando o MinGW desde que abandonei o BCC há mais de 4 anos e não me arrependo, funciona perfeitamente com xHarbour, Harbour, postgres, SQLite, Oracle, GD, etc.

[]'s
Rodrigo
Avatar do usuário
software_facil
Usuário Nível 3
Usuário Nível 3
Mensagens: 211
Registrado em: 23 Fev 2005 12:19
Localização: Curitiba/PR
Contato:

Re: Harbour Teste de Velocidade.

Mensagem por software_facil »

Rodrigo, quando vc tiver um tempo, poderia nos mostrar como usar o GCC com o Harbour !

Abraços

Marcelo Neves
messenger : software_facil@hotmail.com
rodrmigu
Usuário Nível 3
Usuário Nível 3
Mensagens: 150
Registrado em: 27 Nov 2007 15:13
Localização: Indaiatuba SP

Re: Harbour Teste de Velocidade.

Mensagem por rodrmigu »

Olá Marcelo,

Não é nenhum bicho de sete cabeças não. Mas se vc quiser compilar o harbour do SVN, vc precisará usar o MSYS, que é um Shell que "simula" um prompt bash do Linux, permitindo rodar muitas coisas como se fossem em linux.

Se vc usar os binários existentes, daí é mais tranquilo, dá pra usar o próprio DOS pra isso. Aliás, eu uso até no xMate.

Abaixo, existem dois Batches de compilação, um usando DOS e outro o Bash do Msys:

DOS:

Código: Selecionar todos

@echo off

set XHGTK_INCLUDE=..\..\include
set XHGTK_LIB=..\..\lib

if "%1" == "" goto HELP

if "%HB_GT_LIB%" == "" SET HB_GT_LIB=gtwin
if "%HB_PREF%" == ""         goto HELP
if "%GTK_BASEPATH%" == ""    goto HELP
if "%HB_BIN_INSTALL%" == ""  goto HELP
if "%HB_LIB_INSTALL%" == ""  goto HELP
if "%HB_INC_INSTALL%" == ""  goto HELP

if "%HB_COMPILER%" == "mingw"   goto MINGW
if "%HB_COMPILER%" == "mingw32" goto MINGW
if "%HB_COMPILER%" == "msvc"    goto MSVC

goto HELP

:MSVC
if "%INCLUDE%" == ""         goto HELP
if "%LIB%" == ""             goto HELP

rem if "%HB_MT%" == "" set LDFLAGS=/NODEFAULTLIB:LIBCMTD /NODEFAULTLIB:LIBCMT
rem if "%HB_MT%" == "MT" set LDFLAGS=/NODEFAULTLIB:LIBC /NODEFAULTLIB:LIBCP 
rem if "%HB_MT%" == "mt" set LDFLAGS=/NODEFAULTLIB:LIBC /NODEFAULTLIB:LIBCP 

if "%HB_MT%" == "" set CFLAGS= 
if "%HB_MT%" == "MT" set CFLAGS=/MT 
if "%HB_MT%" == "mt" set CFLAGS=/MT

set CFLAGS=%CFLAGS% -TP -W3 /EHsc /D_CRT_SECURE_NO_DEPRECATE /link /FORCE:MULTIPLE /subsystem:windows 
set CFLAGS=%CFLAGS% /libpath:%XHGTK_LIB% /libpath:%GTK_BASEPATH%\lib /libpath:%HB_LIB_INSTALL%

set LIBS=xhgtk.lib gtwin.lib gtgui.lib

if "%HB_PREF%" == "hb" set LIBS=%LIBS% hbdebug.lib  hbvm.lib  hbrtl.lib  hbrdd.lib  hbrtl.lib  hbvm.lib  hbmacro.lib  hbpp.lib  hblang.lib  hbcpage.lib hbcommon.lib  rddntx.lib  rddcdx.lib  rddfpt.lib  hbsix.lib  hbhsx.lib  

if "%HB_PREF%" == "xhb" set LIBS=%LIBS% debug.lib common.lib lang.lib codepage.lib pcrepos.lib vm%HB_MT%.lib rtl%HB_MT%.lib rdd%HB_MT%.lib macro%HB_MT%.lib pp%HB_MT%.lib dbfcdx%HB_MT%.lib dbffpt%HB_MT%.lib dbfntx%HB_MT%.lib hbsix%HB_MT%.lib hsx%HB_MT%.lib  

set LIBS=%LIBS% shell32.lib user32.lib winspool.lib ole32.lib oleaut32.lib ws2_32.lib kernel32.lib 
set LIBS=%LIBS% gdi32.lib comctl32.lib comdlg32.lib

set LIBS=%LIBS% glade-2.0.lib gtk-win32-2.0.lib xml2.lib gdk-win32-2.0.lib atk-1.0.lib gdk_pixbuf-2.0.lib 
set LIBS=%LIBS% pangowin32-1.0.lib pangocairo-1.0.lib cairo.lib pangoft2-1.0.lib fontconfig.lib freetype.lib  
set LIBS=%LIBS% z.lib pango-1.0.lib gobject-2.0.lib gmodule-2.0.lib glib-2.0.lib intl.lib iconv.lib  
	
harbour %1.prg -m -n -q0 -gc -p -w -I%HB_INC_INSTALL% -I%XHGTK_INCLUDE%

cl %1.c -I%HB_INC_INSTALL% %CFLAGS% %LDFLAGS% %LIBS% 

del %1.c
del %1.obj

goto EXIT

:MINGW
set CFLAGS=-W -Wall -O2 -mms-bitfields -mwindows -mno-cygwin 
set CFLAGS=%CFLAGS% -L%XHGTK_LIB% -L%GTK_BASEPATH%\lib -L%HB_LIB_INSTALL%

set LIBS=-Wl,--start-group -lxhgtk -lgtwin -lgtgui 

if "%HB_PREF%" == "hb" set LIBS=%LIBS% -lhbdebug -lhbvm -lhbrtl -lhbrdd -lhbrtl -lhbvm -lhbmacro -lhbpp -lhblang -lhbcpage -lhbcommon -lrddntx -lrddcdx -lrddfpt -lhbsix -lhbhsx -Wl,--end-group

if "%HB_PREF%" == "xhb" set LIBS=%LIBS% -ldebug -lvm -lrtl -llang -lcodepage -lrdd -lmacro -lpp -ldbfntx -ldbfcdx -ldbffpt -lhbsix -lhsx -lcommon -lpcrepos -Wl,--end-group

set LIBS=%LIBS% -lm -luser32 -lwinspool -lole32 -loleaut32 -luuid -lgdi32 -lcomctl32 -lcomdlg32 -lodbc32 

set LIBS=%LIBS% -lglade-2.0 -lgtk-win32-2.0 -lxml2 -lgdk-win32-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lpangowin32-1.0 
set LIBS=%LIBS% -lpangocairo-1.0 -lcairo -lpangoft2-1.0 -lfontconfig -lfreetype -lz -lpango-1.0 -lm -lgobject-2.0 
set LIBS=%LIBS% -lgmodule-2.0 -lglib-2.0 -lintl -liconv  
 
harbour %1.prg -m -n -q0 -gc -p -w -I%HB_INC_INSTALL% -I%XHGTK_INCLUDE%

gcc %1.c -o %1 -I%HB_INC_INSTALL% %CFLAGS% %LIBS% 

del %1.c

goto EXIT

:HELP
   echo.
   echo.
   echo Usage: build filename  - don't use the .prg extention, e.g. build myapp
   echo.
   echo Notes:
   echo.
   echo     PATH:
   echo       - Add the path for harbour binaries as well as Gtk\bin files	
   echo.
   echo     HB_COMPILER:
   echo       - mingw32 (Cygnus/MinGW GNU C, Windows 32-bit) for xHarbour
   echo       - mingw   (Cygnus/MinGW GNU C, Windows 32-bit) for Harbour
   echo       - msvc    (Microsoft Visual C++, Windows 32-bit)
   echo.
   echo     GTK_BASEPATH:
   echo       - Location where is gtk is installed e.g. SET GTK_BASE_PATH=C:\Gtk
   echo.
   echo     HB_PREF:
   echo       - xHarbour (xhb) or Harbour (hb) compiler, e.g. SET HB_PREF=xhb
   echo.
   echo     HB_BIN_INSTALL:
   echo       - Location where the Harbour binaries are installed e.g. SET HB_BIN_INSTALL=C:\xHarbour\bin
   echo.
   echo     HB_LIB_INSTALL:
   echo       - Location where the Harbour libraries are installed e.g. SET HB_LIB_INSTALL=C:\xHarbour\lib
   echo.
   echo     HB_INC_INSTALL:
   echo       - Location where the Harbour include files are installed e.g. SET HB_INC_INSTALL=C:\xHarbour\include 
   echo.
   echo     INCLUDE:
   echo       - msvc only, where are the nclude files locations e.g. C:\Msvc\include
   echo.
   echo     LIB:
   echo       - msvc only, where are the libraries files locations e.g. C:\Msvc\lib
   echo.

:EXIT
Unix Shell:

Código: Selecionar todos

#!/bin/sh

if [ -z "$HB_PREF" ]; then export HB_PREF=hb; fi

if [ -z "$HB_ARCHITECTURE" ]; then export HB_ARCHITECTURE=w32; fi
if [ -z "$HB_GPM_MOUSE" ]; then export HB_GPM_MOUSE=no; fi
if [ -z "$HB_GT_LIB" ]; then export HB_GT_LIB=gtwin; fi

if [ $HB_PREF = hb ]; then
    if [ -z "$HB_COMPILER" ]; then export HB_COMPILER=mingw; fi
    if [ -z "$HB_BIN_INSTALL" ]; then export HB_BIN_INSTALL=/harbour/bin/; fi
    if [ -z "$HB_LIB_INSTALL" ]; then export HB_LIB_INSTALL=/harbour/lib/; fi   
    if [ -z "$HB_INC_INSTALL" ]; then export HB_INC_INSTALL=/harbour/include/; fi
else
    if [ -z "$HB_COMPILER" ]; then export HB_COMPILER=mingw32; fi
    if [ -z "$HB_BIN_INSTALL" ]; then export HB_BIN_INSTALL=/xharbour/bin/; fi
    if [ -z "$HB_LIB_INSTALL" ]; then export HB_LIB_INSTALL=/xharbour/lib/; fi   
    if [ -z "$HB_INC_INSTALL" ]; then export HB_INC_INSTALL=/xharbour/include/; fi
fi

LIBFILES="-Wl,--start-group -lxhgtk "

if [ $HB_PREF = hb ]; then
    LIBFILES="$LIBFILES -lhbdebug -lhbvm -lhbrtl -lhbrdd -lhbrtl -lhbvm -lhbmacro -lhbpp -lhblang -lhbcpage -lhbcommon -lrddntx -lrddcdx -lrddfpt -lhbsix -lhbhsx "
else
    LIBFILES="$LIBFILES -ldebug -lvm -lrtl -llang -lrdd -lmacro -lpp -lcommon -lcodepage -ldbfntx -ldbfcdx -ldbffpt -lhbsix -lhsx -lpcrepos "
fi 

if [ $HB_COMPILER = mingw ]; then
    LIBFILES="$LIBFILES  -lgtwin -lgtgui "
fi

if [ $HB_COMPILER = mingw32 ]; then
    LIBFILES="$LIBFILES  -lgtwin -lgtgui "
fi

if [ $HB_GT_LIB = gttrm ]; then
   LIBFILES="$LIBFILES -lgttrm "
fi

if [ $HB_GT_LIB = gtcrs ]; then
   LIBFILES="$LIBFILES -lgtcrs -lncurses "
fi

if [ $HB_GT_LIB = gtsln ]; then
   LIBFILES="$LIBFILES -lgtsln -lslang "
fi

LIBFILES="$LIBFILES -Wl,--end-group "

if [ $HB_COMPILER = mingw32 ]; then
    CFLAGS="-W -Wall -O2 -mms-bitfields -mwindows -mno-cygwin "
    LIBFILES="$LIBFILES -lm -luser32 -lwinspool -lole32 -loleaut32 -luuid -lgdi32 -lcomctl32 -lcomdlg32 -lodbc32 -lwininet -lwsock32"
else
    CFLAGS="-W -Wall -O2"
fi

if [ -z "$HB_PREF" ]; then
    PKGFILES=`pkg-config --cflags gtk+-2.0 --libs gtk+-2.0 libglade-2.0`
else
    PKGFILES=`pkg-config --cflags gtk+-2.0 --libs gtk+-2.0`
fi

$HB_BIN_INSTALL/harbour -b -a -m -n -w -I$HB_INC_INSTALL -I../../include $1

gcc $1.c -o $1 $CFLAGS -L$HB_LIB_INSTALL -L../../lib -I$HB_INC_INSTALL -I../../include $LIBFILES $PKGFILES

rm -f $1.c
rm -f $1.o

./$1
Note que os exemplos foram extraídos da xhgtk, mas vc pode remover as referencias da lib que irá funcionar. Caso vc use o xMate, eu posso lhe mandar o arquivo de configuração.

Caso vc queira usar com sua aplicação, vc pode também usar algo que eu tenho aqui. Eu tenho um Makefile, e que tudo o que eu coloque na pasta src\ ele irá compilar e linkar, basta colocar o Makefile uma pasta antes do src\

Segue exemplo:

Código: Selecionar todos

INC_DIR = -I/g/xhgtk/include -I/g/gtklib
LIB_DIR = -L/g/gtklib/lib -L/g/xhgtk/lib -L/g/pgsql/lib
OBJ_DIR = obj
SRC_DIR = source
BIN_DIR = bin

LIBFILES += -lgtklib -lxhgtk -lpq -Wl,--start-group -lhbdebug -lhbvm -lhbrtl -lhbrdd -lhbrtl -lhbvm -lhbmacro -lhbpp -lhblang -lhbcpage -lhbcommon -lrddntx -lrddcdx -lrddfpt -lhbsix -lhbhsx -lhbtip -lhbwin -lxhb

ifeq ($(HB_COMPILER),mingw)
   CFLAGS = -Wall -mms-bitfields -mwindows -mno-cygwin
   LFLAGS = -Wall -mms-bitfields -mwindows -mno-cygwin
   LIBFILES += -lgtwin -lgtgui -lgtwvt -Wl,--end-group 
   LIBFILES += -luser32 -lwinspool -lole32 -loleaut32 -luuid -lgdi32 -lcomctl32 -lcomdlg32 -lodbc32 -lws2_32 
   LIBFILES += `pkg-config --libs gtk+-2.0 libglade-2.0`
   FILENAME = $(BIN_DIR)/repman.exe
else
   CFLAGS = -Wall
   LIBFILES += -lgttrm -Wl,--end-group 
   FILENAME = $(BIN_DIR)/repman
endif

CFLAGS += `pkg-config --cflags gtk+-2.0 libglade-2.0` 
CFLAGS += -I$(HB_INC_INSTALL) $(INC_DIR) 

OBJECTS = $(subst $(SRC_DIR),$(OBJ_DIR),$(patsubst %.prg,%.o,$(wildcard $(SRC_DIR)/*.prg)))

dummy : $(OBJECTS)
	gcc $^ -o $(FILENAME) $(LFLAGS) -L$(HB_LIB_INSTALL) $(LIB_DIR) $(LIBFILES) 

all: $(OBJECTS)

obj/%.c: $(SRC_DIR)/%.prg
	harbour -b -a -m -n -w -I$(HB_INC_INSTALL) $(INC_DIR) -o$@ $<

obj/%.o: obj/%.c
	gcc -c $(CFLAGS)-o$@ $<

clean :
	rm -f $(OBJ_DIR)/*.o
	rm -f $(OBJ_DIR)/*.c
	rm -f $(FILENAME)
Para mais detalhes, dá uma olhada neste link abaixo, acho que irá te ajudar:

http://xhgtk.sourceforge.net/config13.html

[]'s
Rodrigo
Avatar do usuário
software_facil
Usuário Nível 3
Usuário Nível 3
Mensagens: 211
Registrado em: 23 Fev 2005 12:19
Localização: Curitiba/PR
Contato:

Re: Harbour Teste de Velocidade.

Mensagem por software_facil »

Rodrigo, eu e os colegas do fórum agradecem sua ajuda !

Abraços

Marcelo Neves
messenger : software_facil@hotmail.com
Responder