Pular para o conteúdo principal

Postagem em destaque

BlackTDN :: Como Criar Relatórios de Cotações com Dados Agrupados Usando SQL

img: DALL·E 2024-08-09 07.00.00 - A high-quality image showcasing a detailed SQL query being written in a code editor, such as VS Code, on a dark theme background. ... ## Como Criar Relatórios de Cotações com Dados Agrupados Usando SQL Quando trabalhamos com sistemas ERP e precisamos gerar relatórios de cotações que apresentam dados de múltiplos fornecedores, é comum encontrarmos a necessidade de pivotar registros que, originalmente, são apresentados de forma vertical. Isso é especialmente útil quando o objetivo é comparar preços ou condições de diferentes fornecedores para um mesmo produto em uma única linha do relatório. Neste artigo, vamos explorar uma abordagem para transformar registros verticais em colunas, facilitando a impressão de relatórios que consolidam informações de vários fornecedores em uma única linha. Vamos utilizar SQL com técnicas de pivotagem, e ao final, mostraremos como estender essa técnica para um número variável de fornecedores. ### Estrutura do Relatór

BlackTDN :: a small memory manager test code (Harbour vs AppServer)

Peguei emprestado um código de teste do Harbour Project, fiz algumas alterações e adaptações para poder usá-lo no Protheus/TotvsTec de forma a verificar sua performance e ter, como referência, os mesmos resultados obtidos a partir dos mesmos testes efetuados com o código compilado pelo Harbour.

Eis o Código:

   1: /*
   2:  * $Id: memtst.prg 13932 2010-02-20 11:57:17Z vszakats $
   3:  */
   4:  
   5: /*
   6:  *    Harbour Project source code:
   7:  *    a small memory manager test code
   8:  */
   9: #define N_LOOPS      (1000*1000)
  10: #define N_MAXLOOP             10
  11: #define WHITE_SPACE         1024
  12: #define MAX_SIZE_ARRAY    100000
  13:  
  14: #ifndef HB_SYMBOL_UNUSED
  15:     #define HB_SYMBOL_UNUSED( symbol ) ( symbol := ( symbol ) )
  16: #endif
  17:  
  18: #ifdef __HARBOUR__
  19:     #include "simpleio.ch"
  20:     #include "hbmemory.ch"
  21: #else
  22:     #xcommand ?  [<list,...>] => ConOut( [ <list> ] )
  23:     #xcommand ?? [<list,...>] => ConOut( [ <list> ] )
  24:     #xtranslate hb_secondsCPU() => seconds()
  25:     #ifdef TOTVS
  26:         #include "totvs.ch"
  27:     #else
  28:         #include "protheus.ch"
  29:     #endif    
  30: #endif
  31: //-----------------------------------------------------------------------------------------------------------
  32: #ifdef __HARBOUR__
  33: procedure main()
  34:     local cCRLF        := hb_OsNewLine()
  35:     local cVersion     := VERSION()+build_mode()
  36:     local cOS          := OS()
  37: #else
  38: user function memtst()
  39:     local cCRLF        := CRLF
  40:     local cVersion     := "TOTVS APPServer " + GetVersao(.T.,.F.) + " " + GetBuild() + " " + GetRPORelease()
  41:     local cOS          := IF( IsSrvUnix() , "Unix/Linux", "Windows" )    
  42: #endif
  43:     local dDate
  44:     local cTime
  45:     local t
  46:     local nCPUSec
  47:     local nRealSec
  48:     local nSizeArr     := 100
  49:     local cWSpace      := ""
  50:     local nfhandle
  51:  
  52:     SET DATE TO BRITISH
  53:     SET CENTURY ON
  54:  
  55:     for t := 1 to N_MAXLOOP
  56:     
  57:         nRealSec    := seconds()
  58:         nCPUSec     := hb_secondsCPU()
  59:     
  60:         nfhandle    := fCreate( "memtst" + StrZero(t,10) + ".log" )
  61:         IF ( nfhandle < 0 )
  62:             ? "Can not start a test: " + Str( t )
  63:             loop
  64:         EndIF
  65:     
  66:         dDate := date()
  67:         cTime := Time()
  68:     
  69:         ? dDate, cTime, cVersion+", "+cOS
  70:         fWrite( nfhandle , dtoc( dDate ) + ", " + cTime + ", " + cVersion+", "+cOS + cCRLF )
  71:     
  72:         #ifdef __HARBOUR__
  73:             if MEMORY( HB_MEM_USEDMAX ) != 0
  74:                 ?
  75:                fWrite( nfhandle , cCRLF )
  76:                ? "Warning !!! Memory statistic enabled."
  77:                fWrite( nfhandle , "Warning !!! Memory statistic enabled." + cCRLF )
  78:             endif
  79:         #endif
  80:  
  81:         nSizeArr    := Min( nSizeArr * 10 , MAX_SIZE_ARRAY )
  82:         cWSpace     := Space( t * WHITE_SPACE  )
  83:  
  84:         ?
  85:         fWrite( nfhandle , cCRLF )
  86:         
  87:         fWrite( nfhandle , "Len( cWSpace ) :" + Transform( Len( cWSpace ) , "9999999999" ) + cCRLF )
  88:         
  89:         fWrite( nfhandle , cCRLF )
  90:  
  91:         memtst(@nfhandle,@cCRLF,@t,@nSizeArr,@cWSpace)
  92:  
  93:         dDate       := date()
  94:         cTime       := Time()
  95:         nCPUSec     := hb_secondsCPU() - nCPUSec
  96:         nRealSec    := seconds() - nRealSec
  97:  
  98:         ?
  99:         fWrite( nfhandle , cCRLF )        
 100:  
 101:         ? dDate, cTime, cVersion+", "+cOS
 102:         fWrite( nfhandle , dtoc( dDate ) + ", " + cTime + ", " + cVersion+", "+cOS + cCRLF )
 103:  
 104:         ?
 105:         fWrite( nfhandle , cCRLF )
 106:       
 107:         ? " CPU time (total):", nCPUSec, "sec."
 108:         fWrite( nfhandle , " CPU time (total):" + Transform(  nCPUSec , "99999.9999999999" )  + " sec." + cCRLF )
 109:         
 110:         ? "real time (total):", nRealSec, "sec."
 111:         fWrite( nfhandle , "real time (total):" + Transform( nRealSec , "99999.9999999999" ) + " sec." + cCRLF  )
 112:  
 113:         fClose( nfhandle )
 114:  
 115:     next t
 116:  
 117:     cWSpace := NIL
 118:  
 119: Return
 120: //-----------------------------------------------------------------------------------------------------------
 121: Static procedure memtst(nfhandle,cCRLF,t,nSizeArr,cWSpace)
 122:  
 123:     local i
 124:     local a
 125:     local nCPUSec
 126:     local nRealSec
 127:     local nCRLF
 128:     local lFree := .F.
 129:     
 130:     ?
 131:     fWrite( nfhandle , cCRLF )
 132:     ? "testing single large memory blocks allocation and freeing..."
 133:     fWrite( nfhandle , "testing single large memory blocks allocation and freeing..."+ cCRLF )    
 134:     
 135:     ?
 136:     fWrite( nfhandle , cCRLF )
 137:     
 138:     nRealSec    := seconds()
 139:     nCPUSec     := hb_secondsCPU()
 140:  
 141:     for i := 1 to ( t * N_LOOPS )
 142:         a := cWSpace
 143:         HB_SYMBOL_UNUSED( a )
 144:         a := ""
 145:         HB_SYMBOL_UNUSED( a )
 146:         a := NIL
 147:     next i
 148:  
 149:     nCPUSec     := hb_secondsCPU() - nCPUSec
 150:     nRealSec    := seconds() - nRealSec
 151:  
 152:     ? " CPU time:", nCPUSec, "sec."
 153:     fWrite( nfhandle , " CPU time:" + Transform(  nCPUSec , "99999.9999999999" )  + " sec." + cCRLF )    
 154:     
 155:     ? "real time:", nRealSec, "sec."
 156:     fWrite( nfhandle , "real time:" + Transform( nRealSec , "99999.9999999999" ) + " sec." + cCRLF )    
 157:     
 158:     ?
 159:     fWrite( nfhandle , cCRLF )
 160:    
 161:     ? "testing many large memory blocks allocation and freeing..."     
 162:     ?
 163:    
 164:     fWrite( nfhandle , cCRLF )
 165:     fWrite( nfhandle , "testing many large memory blocks allocation and freeing..." + cCRLF )    
 166:     
 167:     ?
 168:     fWrite( nfhandle , cCRLF )
 169:  
 170:     nRealSec    := seconds()
 171:     nCPUSec     := hb_secondsCPU()
 172:     a           := Array(nSizeArr)
 173:     nCRLF       := 0
 174:     for i := 1 to ( t * N_LOOPS )
 175:         a[ i % 100 + 1 ] := cWSpace
 176:         fWrite( nfhandle , Transform( i % 100 + 1  , "9999999999" ) )
 177:         IF ( ( ++nCRLF % 10 ) == 0 )
 178:             fWrite( nfhandle , cCRLF )    
 179:         EndIF
 180:         if i % 200 == 0
 181:             fWrite( nfhandle , cCRLF )
 182:             IF ( lFree )
 183:                 lFree := .F.
 184:                 afill(a,"")
 185:                 ? "Free  :",i
 186:                 fWrite( nfhandle , "Free  : " + Transform( i  , "9999999999" ) + cCRLF )
 187:             Else
 188:                 lFree := .T.
 189:                 afill(a,cWSpace)
 190:                 ? "Alloc :",i
 191:                 fWrite( nfhandle , "Alloc : " + TransForm( i  , "9999999999" ) + cCRLF )
 192:             EndIF
 193:             fWrite( nfhandle , cCRLF )
 194:         endif
 195:     next i
 196:  
 197:     aSize( a , 0 )
 198:     a           := NIL
 199:     nCPUSec     := hb_secondsCPU() - nCPUSec
 200:     nRealSec    := seconds() - nRealSec
 201:  
 202:     ? " CPU time:", nCPUSec, "sec."
 203:     fWrite( nfhandle , " CPU time:" + Transform( nCPUSec  , "99999.9999999999" )  + " sec." + cCRLF )    
 204:     
 205:     ? "real time:", nRealSec, "sec."
 206:     fWrite( nfhandle , "real time:" + Transform( nRealSec  , "99999.9999999999" ) + " sec." + cCRLF )
 207:     
 208:     ?
 209:     fWrite( nfhandle , cCRLF )
 210:  
 211:     ? "testing large memory block reallocation with intermediate allocations..."
 212:  
 213:     fWrite( nfhandle , "testing large memory block reallocation with intermediate allocations..." + cCRLF )
 214:  
 215:     ? "Warning!!! some compilers may badly fail here"
 216:  
 217:     ?
 218:     fWrite( nfhandle , cCRLF )
 219:     
 220:     fWrite( nfhandle , "Warning!!! some compilers may badly fail here" + cCRLF )
 221:  
 222:     ?
 223:     fWrite( nfhandle , cCRLF )
 224:  
 225:     IdleSleep( 2 )
 226:     
 227:     nRealSec    := seconds()
 228:     nCPUSec     := hb_secondsCPU()
 229:     nCRLF       := 0
 230:     a           := Array(0)
 231:     for i := 1 to ( t * N_LOOPS )
 232:         aadd( a, { cWSpace } )
 233:         if i%1000 == 0
 234:             ?? i
 235:             fWrite( nfhandle , Transform( i  , "9999999999" ) )
 236:             if ( ( ++nCRLF % 10 ) == 0 )
 237:                 fWrite( nfhandle , cCRLF )    
 238:             endif
 239:         endif
 240:     next i
 241:  
 242:     fWrite( nfhandle , cCRLF )    
 243:     aSize( a , 0 )
 244:     a           := NIL
 245:     nCPUSec     := hb_secondsCPU() - nCPUSec
 246:     nRealSec    := seconds() - nRealSec
 247:  
 248:     ? " CPU time:", nCPUSec, "sec."
 249:     fWrite( nfhandle , " CPU time:" + Transform( nCPUSec  , "99999.9999999999" )  + " sec." + cCRLF )
 250:     
 251:     ? "real time:", nRealSec, "sec."
 252:     fWrite( nfhandle , "real time:" + Transform( nRealSec  , "99999.9999999999" ) + " sec." + cCRLF )
 253:     
 254:     IdleSleep( 2 )
 255:  
 256: return
 257: //-----------------------------------------------------------------------------------------------------------
 258: static procedure IdleSleep( n )
 259:     #ifdef __HARBOUR__
 260:         n += seconds()
 261:         while seconds() < n
 262:         enddo
 263:     #else
 264:         Sleep( n )
 265:     #endif
 266: return
 267: //-----------------------------------------------------------------------------------------------------------
 268: #ifndef PROTHEUS
 269:     #ifndef TOTVS
 270:         static function build_mode()
 271:         #ifdef __CLIP__
 272:            return " (MT)"
 273:         #else
 274:            #ifdef __XHARBOUR__
 275:               return iif( HB_MULTITHREAD(), " (MT)", "" ) + ;
 276:                      iif( MEMORY( HB_MEM_USEDMAX ) != 0, " (FMSTAT)", "" )
 277:            #else
 278:               #ifdef __HARBOUR__
 279:                  return iif( HB_MTVM(), " (MT)", "" ) + ;
 280:                         iif( MEMORY( HB_MEM_USEDMAX ) != 0, " (FMSTAT)", "" )
 281:               #else
 282:                  #ifdef __XPP__
 283:                     return " (MT)"
 284:                  #else
 285:                     return ""
 286:                  #endif
 287:               #endif
 288:            #endif
 289:         #endif
 290:     #endif
 291: #endif 

O AppServer, até certo ponto,  se saiu bem: mas não agüentou o tranco. Logo mais publico os resultados.


Se alguém puder testar em uma máquina mais parruda e puder me enviar os logs e um resumo de como o AppServer se comportou bem como  das características do ambiente de teste publico junto com os resultados apresentados em meu micrinho xing-ling.


Para baixar o original, siga o link: Source path:svn/trunk/harbour/samples/tests/memtst/memtst.prg



[]s
иαldσ dj

Comentários

Postagens mais visitadas