add more spacing
[personal-kdebase.git] / workspace / kwin / tools / decobenchmark / main.cpp
blobe45663f4da0b16e01a85bca5f06f0dc4660a25a5
1 /*
3 * Copyright (c) 2005 Sandro Giessl <sandro@giessl.com>
4 * Copyright (c) 2005 Luciano Montanaro <mikelima@cirulla.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "main.h"
23 #include <QTimer>
25 #include <kdebug.h>
26 #include <kconfig.h>
27 #include <kdecoration_plugins_p.h>
28 #include <kdecorationfactory.h>
30 #include <time.h>
31 #include <sys/timeb.h>
32 #include <iostream>
35 #include <kaboutdata.h>
36 #include <kapplication.h>
37 #include <kcmdlineargs.h>
39 #include "preview.h"
41 DecoBenchApplication::DecoBenchApplication(const QString &library, Tests tests, int count) :
42 m_tests(tests),
43 m_count(count)
45 KConfig kwinConfig("kwinrc");
46 kwinConfig.setGroup("Style");
48 plugins = new KDecorationPreviewPlugins( &kwinConfig );
49 preview = new KDecorationPreview( plugins, 0 );
51 if (plugins->loadPlugin(library) )
52 kDebug(1212) << "Decoration library " << library << " loaded...";
53 else
54 kError(1212) << "Error loading decoration library " << library << "!" << endl;
56 if (preview->recreateDecoration() )
57 kDebug(1212) << "Decoration created...";
58 else
59 kError(1212) << "Error creating decoration!" << endl;
61 preview->show();
64 DecoBenchApplication::~DecoBenchApplication()
66 delete preview;
67 delete plugins;
70 void DecoBenchApplication::executeTest()
72 clock_t stime = clock();
73 timeb astart, aend;
74 ftime(&astart);
76 if (m_tests == AllTests || m_tests == RepaintTest)
77 preview->performRepaintTest(m_count);
78 if (m_tests == AllTests || m_tests == CaptionTest)
79 preview->performCaptionTest(m_count);
80 if (m_tests == AllTests || m_tests == ResizeTest)
81 preview->performResizeTest(m_count);
82 if (m_tests == AllTests || m_tests == RecreationTest)
83 preview->performRecreationTest(m_count);
85 clock_t etime = clock();
86 ftime(&aend);
88 long long time_diff = (aend.time - astart.time)*1000+aend.millitm - astart.millitm;
89 kDebug(1212) << "Total:" << (float(time_diff)/1000);
90 quit();
93 int main(int argc, char** argv)
95 QString style = "keramik";
96 // KApplication app(argc, argv);
97 KAboutData about("decobenchmark", 0, ki18n("DecoBenchmark"), "0.1", ki18n("kwin decoration performance tester..."), KAboutData::License_LGPL, ki18n("(C) 2005 Sandro Giessl"));
98 KCmdLineArgs::init(argc, argv, &about);
100 KCmdLineOptions options;
101 options.add("+decoration", ki18n("Decoration library to use, such as kwin3_plastik."));
102 options.add("+tests", ki18n("Which test should be executed ('all', 'repaint', 'caption', 'resize', 'recreation')"));
103 options.add("+repetitions", ki18n("Number of test repetitions."));
104 KCmdLineArgs::addCmdLineOptions( options );
106 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
108 if (args->count() != 3)
109 KCmdLineArgs::usage("Wrong number of arguments!");
111 QString library = QString(args->arg(0) );
112 QString t = QString(args->arg(1) );
113 int count = QString(args->arg(2) ).toInt();
115 Tests test;
116 if (t == "all")
117 test = AllTests;
118 else if (t == "repaint")
119 test = RepaintTest;
120 else if (t == "caption")
121 test = CaptionTest;
122 else if (t == "resize")
123 test = ResizeTest;
124 else if (t == "recreation")
125 test = RecreationTest;
126 else
127 KCmdLineArgs::usage("Specify a valid test!");
129 DecoBenchApplication app(library, test, count);
131 QTimer::singleShot(0, &app, SLOT(executeTest()));
132 app.exec();
134 #include "main.moc"
136 // kate: space-indent off; tab-width 4;