Initial commit
[www-passmark.git] / lib / WWW / Passmark.pm
CommitLineData
e7d8c919
MG
1package WWW::Passmark;
2
3use 5.014000;
4use strict;
5use warnings;
6use parent qw/Exporter/;
7
8our $VERSION = '0.001';
9our @EXPORT_OK = qw/get_cpu_list get_gpu_list/;
10our @EXPORT = @EXPORT_OK;
11
12use WWW::Passmark::CPU;
13use WWW::Passmark::GPU;
14
15use HTML::TreeBuilder;
16use LWP::UserAgent; # TreeBuilder->new_from_url uses this
17use List::MoreUtils qw/natatime/;
18
19use Data::Dumper qw/Dumper/;
20
21our $CPU_URL = 'https://www.cpubenchmark.net/CPU_mega_page.html';
22our $GPU_URL = 'https://www.videocardbenchmark.net/GPU_mega_page.html';
23
24sub get_main_table {
25 my ($url) = @_;
26 my $tree = HTML::TreeBuilder->new_from_url($url);
27 my $table = $tree->look_down(class => 'tablesorter');
28 my $iter = natatime 2, $tree->find('tbody')->find('tr');
29
30 my @results;
31 while (my @items = $iter->()) {
32 my ($item, $desc) = @items;
33 push @results, [ map { $_->as_text } $item->find('td'), $desc->find('td') ]
34 }
35
36 @results
37}
38
39sub get_cpu_list {
40 my @results = map { bless $_, 'WWW::Passmark::CPU' } get_main_table $CPU_URL;
41 #bless \@results, 'WWW::Passmark::CPUList'
42 \@results
43}
44
45sub get_gpu_list {
46 my @results = map { bless $_, 'WWW::Passmark::GPU' } get_main_table $GPU_URL;
47 #bless \@results, 'WWW::Passmark::GPUList'
48 \@results
49}
50
511;
52__END__
53
54=encoding utf-8
55
56=head1 NAME
57
58WWW::Passmark - look up CPU/GPU benchmark results
59
60=head1 SYNOPSIS
61
62 use WWW::Passmark;
63 my $cpu_list = get_cpu_list;
64 my $some_cpu = $cpu_list->[232];
65 say $some_cpu->name; # AMD Ryzen 7 2700X
66 say $some_cpu->socket; # AM4
67 say $some_cpu->cpumark; # 17016
68 say $some_cpu->test_date; # Apr 2018
69
70 my $gpu_list = get_gpu_list;
71 my $some_gpu = $gpu_list->[5];
72 say $some_gpu->name; # Radeon R9 Fury
73 say $some_gpu->g3dmark; # 9212
74
75=head1 DESCRIPTION
76
77This module is a scraper for Passmark software result websites. This
78is the first version of the module, which only supports two of the
79websites (cpubenchmark.net and videocardbenchmark.net) and offers few
80features.
81
82There are currently two functions, both exported by default. They are
83B<get_cpu_list> and B<get_gpu_list>, which download the list of all
84benchmark results for CPUs/GPUs and return an arrayref of objects of
85type L<WWW::Passmark::CPU> or L<WWW::Passmark::GPU>. Each such object
86represents one CPU/GPU, and contains its name and benchmark results.
87
88=head1 SEE ALSO
89
90L<https://www.cpubenchmark.net>, L<https://www.videocardbenchmark.net>
91
92=head1 AUTHOR
93
94Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
95
96=head1 COPYRIGHT AND LICENSE
97
98Copyright (C) 2018 by Marius Gavrilescu
99
100This library is free software; you can redistribute it and/or modify
101it under the same terms as Perl itself, either Perl version 5.24.1 or,
102at your option, any later version of Perl 5 you may have available.
103
104
105=cut
This page took 0.014875 seconds and 4 git commands to generate.