Olá Márcio,
Com o Java, JavaScript e BeanShell, não.
Segue o código BASIC e Python. São dois testes, um com chamadas da API e
outro sem.
REM =====>  Inicio código BASIC
' TESTA VELOCIDADE DO BASIC
Const EPSILON# = 1E-14
Sub teste_API_Basic
' Teste com chamadas da API do LibreOffice
'
     Dim num As Double
     h1 = timevalue (time())
     sURL = "private:factory/scalc"
     oDoc = StarDesktop.loadComponentFromURL(sURL,"_blank",0,Array())
     oPlan = oDoc.getSheets().getByIndex(0)
     oCel = oPlan.getCellByPosition(0,0)
     oCel.setString("NÚMERO")
     oCel = oPlan.getCellByPosition(1,0)
     oCel.setString("RAIZ 1")
     oCel = oPlan.getCellByPosition(2,0)
     oCel.setString("RAIZ 2")
     for i = 1 to 10000
         rr1 = raizQuadrada (i)
         rr2 = sqr (i)
         oCel = oPlan.getCellByPosition(0,i)
         oCel.setValue(i)
         oCel = oPlan.getCellByPosition(1,i)
         oCel.setValue(rr1)
         oCel = oPlan.getCellByPosition(2,i)
         oCel.setValue(rr2)
     next i
     h2 = timevalue (time())
     tempo = h2 - h1
     hora = hour(tempo) : min = minute (tempo) : seg = second (tempo)
     oCel = oPlan.getCellByPosition(5,0)
     oCel.setString(str(hora)&":"&str(min)&":"&str(seg))
     print "FIM DO PROCESSAMENTO"
End Sub
Sub teste_Basic
' Teste sem chamadas da API do LibreOffice
'
     Dim num As Double
     Dim i As Double
     Dim soma As Double
     soma = 0
     h1 = timevalue (time())
     for i = 1 to 100000
         rr1 = raizQuadrada (i)
         rr2 = sqr (i)
         soma = soma + rr1 + rr2
     next i
     h2 = timevalue (time())
     tempo = h2 - h1
     hora = hour(tempo) : min = minute (tempo) : seg = second (tempo)
     ' escreve resultado
     sURL = "private:factory/scalc"
     oDoc = StarDesktop.loadComponentFromURL(sURL,"_blank",0,Array())
     oPlan = oDoc.getSheets().getByIndex(0)
     oCel = oPlan.getCellByPosition(0,0)
     oCel.setString(str(hora)&":"&str(min)&":"&str(seg))
     oCel = oPlan.getCellByPosition(1,0)
     oCel.setValue(soma)
     print "FIM DO PROCESSAMENTO"
End Sub
Function raizQuadrada (numero As Double) As Double
' retorna raiz quadrada do numero (metodo babilônico)
     Dim nova As Double
     Dim anterior As Double
     If numero = 0 Then
         raizQuadrada = 0
         Exit Function
     End If
     nova = numero
     Do
         anterior = nova
         nova = (anterior + numero / anterior) / 2
     Loop While(Abs (nova - anterior)>  EPSILON)
     raizQuadrada = nova
End Function
REM ======>  FIM CÓDIGO BASIC
# =====>  INICIO CODIGO PYTHON
# teste de macro PyUNO para LibreOffice
# calcula e escreve numa planilha as raizes de 1 a 10000
from math import sqrt
from time import time, strftime, gmtime
def raizQuadrada(numero):
     #calcula a raiz quadrada de numero
     epsilon = 1E-14
     if (numero == 0):
         return (0)
         #
     nova = numero
     anterior = 0
     while ( abs (nova - anterior)>  epsilon):
         anterior = nova
         nova = (anterior + numero / anterior) / 2.0
         #
     return nova
def testePy():
     #Escreve as raizess de 1 a 10000 numa nova planilha
     desktop = XSCRIPTCONTEXT.getDesktop()
     h1 = time()
     sURL = "private:factory/scalc"
     oDoc = desktop.loadComponentFromURL( sURL,"_blank", 0, () )
     oPlan = oDoc.getSheets().getByIndex(0)
     oCel = oPlan.getCellByPosition(0,0)
     oCel.setString("NUMERO")
     oCel = oPlan.getCellByPosition(1,0)
     oCel.setString("RAIZ 1")
     oCel = oPlan.getCellByPosition(2,0)
     oCel.setString("RAIZ 2")
     for i in range(1,10001,1):
         rr1 = raizQuadrada (i)
         rr2 = sqrt (i)
         oCel = oPlan.getCellByPosition(0,i)
         oCel.setValue(i)
         oCel = oPlan.getCellByPosition(1,i)
         oCel.setValue(rr1)
         oCel = oPlan.getCellByPosition(2,i)
         oCel.setValue(rr2)
         #
     h2 = time()
     tempo = strftime("%H:%M:%S",gmtime(h2 - h1))
     oCel = oPlan.getCellByPosition(5,0)
     oCel.setString(tempo)
def testePyLoop():
     # testa loop for da PyUNO
     #
     soma = 0.0
     h1 = time()
     for i in range(1, 100000, 1):
         rr1 = raizQuadrada (i)
         rr2 = sqrt (i)
         soma = soma + rr1 + rr2
     #
     h2 = time()
     tempo = strftime("%H:%M:%S",gmtime(h2 - h1))
     #
     sURL = "private:factory/scalc"
     desktop = XSCRIPTCONTEXT.getDesktop()
     oDoc = desktop.loadComponentFromURL(sURL,"_blank",0,())
     oPlan = oDoc.getSheets().getByIndex(0)
     oCel = oPlan.getCellByPosition(0,0)
     oCel.setString(tempo)
     oCel = oPlan.getCellByPosition(1,0)
     oCel.setValue(soma)
# define as funcoes visiveis na interface grafica do BrOffice.org
g_exportedScripts = (testePy, testePyLoop)
# ====>  FIM CÓDIGO PYTHON
Att.
--
Noelson
Em 22 de maio de 2011 10:00, Marcio F. Minicz<minicz@uol.com.br>  escreveu:
Noelson,
Obrigado pelo retorno. Você pode passar cópia dos programas?
Também fiz um teste. Criei uma pequena macro que só executa um laço for,
10.000.000 iterações, dentro do laço vazio. Em Python levou 0,953 segundos e
em Basic 0,00015 segundos. O interessante é que a sensação de velocidade foi
o oposto, imagino que é devido ao tempo de carga das bibliotecas.
Vc já fez algum comparativo com Java?
Márcio Minicz
On 17/05/11 20:49, Noelson Duarte wrote:
Olá Márcio,
Esta é uma dúvida antiga que eu também tinha. Então escrevi algum código
para tentar esclarecê-la.
O problema resolvido foi simples: calcular a raiz quadrada de 1 a 10000,
usando o método de Newton e as funções das linguagens e escrevendo o
número
e suas raízes numa planilha do Calc (totalizando 30.000 células).
Eis o tempo de cada macro:
Basic ... 0h 0m 54s
Python . 0h 0m 46s
Portanto, uma ligeira vantagem para o Python, talvez devido a um melhor
desempenho nos loops.
Att.
--
Noelson
PS: se alguém quiser melhorar o código, envio para a lista.
Em 14 de maio de 2011 20:51, Marcio F. Minicz<minicz@uol.com.br>
  escreveu:
  Pessoal,
Alguém sabe dizer qual é a diferença de desempenho entre uma macro para
Calc feita em Basic ou em Python?
Abraço.
Márcio Minicz
--
Você está recebendo e-mails da lista usuarios@pt-br.libreoffice.org
# Informações sobre os comandos disponíveis (em inglês):
  mande e-mail vazio para usuarios+help@pt-br.libreoffice.org
# Cancelar sua assinatura: mande e-mail vazio para:
  usuarios+unsubscribe@pt-br.libreoffice.org
# Arquivo de mensagens:
http://listarchives.libreoffice.org/pt-br/usuarios/
  Privacy Policy |
  
Impressum (Legal Info) |
  
Copyright information: Unless otherwise specified, all text and images
  on this website are licensed under the
  
Creative Commons Attribution-Share Alike 3.0 License.
  This does not include the source code of LibreOffice, which is
  licensed under the Mozilla Public License (
MPLv2).
  "LibreOffice" and "The Document Foundation" are
  registered trademarks of their corresponding registered owners or are
  in actual use as trademarks in one or more countries. Their respective
  logos and icons are also subject to international copyright laws. Use
  thereof is explained in our 
trademark policy.